Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Add a submenu to the system menu of a program Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
23-Nov-03
Category
System
Language
Delphi 3.x
Views
145
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			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;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC