Author: Tomas Rutkauskas I'm trying to insert a submenu into my application's system menu. Anyone have a code example of adding a submenu and menu items underneath that new submenu? Answer: Here's some sample code to play with: 1 { ... } 2 3 procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND; 4 { ... } 5 6 const 7 SC_ITEM = $FF00; {Should be a multiple of 16} 8 9 procedure TForm1.WMSysCommand(var Msg: TWMSysCommand); 10 begin 11 {See if this is a command we added} 12 if (Msg.CmdType and $FFF0) = SC_ITEM then 13 begin 14 ShowMessage('Item command received'); 15 Msg.Result := 0; 16 end 17 else 18 inherited; 19 end; 20 21 procedure TForm1.FormCreate(Sender: TObject); 22 var 23 MenuItemInfo: TMenuItemInfo; 24 PopupMenu: HMENU; 25 Result: Boolean; 26 SysMenu: HMenu; 27 begin 28 {Create the popup menu} 29 PopupMenu := CreatePopupMenu; 30 Assert(PopupMenu <> 0); 31 {Insert an item into it} 32 FillChar(MenuItemInfo, SizeOf(MenuItemInfo), 0); 33 with MenuItemInfo do 34 begin 35 cbSize := SizeOf(MenuItemInfo); 36 fMask := MIIM_TYPE or MIIM_ID; 37 fType := MFT_STRING; 38 wID := SC_ITEM; 39 dwTypeData := PChar('Item'); 40 cch := 4; {'Item' is 4 chars} 41 end; 42 Result := InsertMenuItem(PopupMenu, 0, True, MenuItemInfo); 43 Assert(Result, 'InsertMenuItem failed'); 44 {Insert the popup into the system menu} 45 FillChar(MenuItemInfo, SizeOf(MenuItemInfo), 0); 46 with MenuItemInfo do 47 begin 48 cbSize := SizeOf(MenuItemInfo); 49 fMask := MIIM_SUBMENU or MIIM_TYPE; 50 fType := MFT_STRING; 51 hSubMenu := PopupMenu; 52 dwTypeData := PChar('SubMenu'); 53 cch := 7; {'SubMenu' is 7 chars} 54 end; 55 SysMenu := GetSystemMenu(Handle, False); 56 Assert(SysMenu <> 0); 57 Result := InsertMenuItem(SysMenu, GetMenuItemCount(SysMenu), True, MenuItemInfo); 58 Assert(Result, 'InsertMenuItem failed'); 59 end;