size : 3482 uploaded_on : Thu Apr 1 00:00:00 1999 modified_on : Wed Dec 8 14:03:37 1999 title : Accessing system menu org_filename : XSSysMenu.txt author : Bjoerge Saether authoremail : bsaether@online.no description : How to modify the system menu keywords : tested : not tested yet submitted_by : The CKB Crew submitted_by_email : ckb@netalive.org uploaded_by : nobody modified_by : nobody owner : nobody lang : plain file-type : text/plain category : delphi-commoncontrols-menus __END_OF_HEADER__ >I want to add items to the form's system menu. >I can add to a menu, but I can't get the systems menu (minimise, max, close, >etc...) Here is a fragment of something I wrote... type TScreenForm = class(TForm) DummyPopup: TPopupMenu; // I use this to create a popupmenu (because I knew how to do this, although it could be done in a pure WinAPI manner private FFtDef: Pointer; FHSysMenu : HWnd; FPopupCount: integer; procedure WMSysMenu(var Message: TWMSysCommand); message WM_SYSCOMMAND; public function FindFontItem(ACmd: integer): TMenuItem; procedure ModifySysMenu(APopup: TPopupMenu); end; implementation {$R *.DFM} // uses some odd units... function TScreenForm.FindFontItem(ACmd: integer): TMenuItem; var i: integer; begin result:=nil; for i:=0 to DummyPopup.Items.Count-1 do if DummyPopup.Items[i].Command = ACmd then begin result:=DummyPopup.Items[i]; break; end; end; procedure TScreenForm.WMSysMenu(var Message: TWMSysCommand); var IsFontItem: boolean; AItem : TMenuItem; Flags : integer; begin with Message do begin result:=1; case CmdType of SC_MAXIMIZE, VSC_MAXIMIZEDBLCLICK, SC_MINIMIZE, VSC_MINIMIZEDBLCLICK, SC_CLOSE, SC_RESTORE: inherited; else begin if CmdType >= $F000 then result:=1 else if FPopupCount > 0 then begin result:=0; AItem:=FindFontItem(CmdType); IsFontItem:=AItem <> nil; if AItem = nil then AItem:=GetScreenWindow(self).FindPopupItem(CmdType); if XPos < 10000 then AItem.OnClick(AItem); Flags:=MF_BYCOMMAND or MF_ENABLED; if not IsFontItem then begin if AItem.Checked then Flags:=Flags or MF_CHECKED; ModifyMenu(FHSysMenu, CmdType, Flags, CmdType, PChar(AItem.Caption)); end; end; end; end; if result = 1 then inherited; end; end; procedure TScreenForm.ModifySysMenu(APopup: TPopupMenu); // Adds all the items from this popup to the system menu... var i, j : integer; MenuFlags: integer; AItem, ASubItem : TMenuItem; AMenuItem: TMenuItem; begin FPopupCount:=APopup.Items.count; FHSysMenu:=GetSystemMenu(handle, false); AppendMenu(FHSysMenu, MF_BYPOSITION or MF_SEPARATOR, 0, ''); for i:=0 to APopup.Items.count-1 do begin AItem:=TMenuItem(APopup.Items[i]); if GetScreenWindow(self).TextScreen.Client.IsExploded and (AItem.Caption = 'Form') then AItem.Enabled:=false; MenuFlags:=MF_BYCOMMAND; if AItem.Enabled then MenuFlags:=MenuFlags or MF_ENABLED else MenuFlags:=MenuFlags or MF_DISABLED or MF_CHECKED or MF_GRAYED; if AItem.Checked then MenuFlags:=MenuFlags or MF_CHECKED; if AItem.Caption = '-' then MenuFlags:=MenuFlags or MF_SEPARATOR; if AItem.Count > 0 then begin MenuFlags:=MenuFlags or MF_POPUP; AMenuItem:=TMenuItem.create(APopup); for j:=0 to AItem.Count-1 do begin ASubItem:=TMenuItem.create(DummyPopup); ASubItem.Caption:=AItem.Items[j].Caption; ASubItem.OnClick:=AItem.Items[j].OnClick; ASubItem.Tag:=AItem.Items[j].Tag; DummyPopup.Items.Add(ASubItem); end; AppendMenu(FHSysMenu, MenuFlags, DummyPopup.Handle, PChar(AItem.Caption)); end else AppendMenu(FHSysMenu, MenuFlags, AItem.Command, PChar(AItem.Caption)); end; end; end.