Articles   Members Online:
-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 menu item to the Windows Taskbar popup menu 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
03-Oct-02
Category
VCL-Menu
Language
Delphi 2.x
Views
84
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I want to add a menu item to the menu, which pops up when you right-click on the 
taskbar button for your application. I know how to add item to form system menu, 
but it doesn't change the popup menu on the taskbar.

Answer:

Solve 1:

1   unit Unit1;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7     StdCtrls, ExtCtrls;
8   
9   const
10    idSysAbout = 100;
11  
12  type
13    TForm1 = class(TForm)
14      procedure FormCreate(Sender: TObject);
15    public
16      procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
17    end;
18  
19  var
20    Form1: TForm1;
21  
22  implementation
23  
24  {$R *.DFM}
25  
26  procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
27  begin
28    if (Msg.message = WM_SYSCOMMAND) and (Msg.WParam = idSysAbout) then
29    begin
30      ShowMessage('This is a test');
31      Handled := True;
32    end;
33  end;
34  
35  procedure TForm1.FormCreate(Sender: TObject);
36  begin
37    AppendMenu(GetSystemMenu(Application.Handle, False), MF_SEPARATOR, 0, '');
38    AppendMenu(GetSystemMenu(Application.Handle, False), MF_STRING, idSysAbout, 
39  'Test');
40    Application.OnMessage := AppMessage;
41  end;
42  
43  end.



Solve 2:

The popup menu for a Taskbar button is the Application windows system menu. To add 
items to it you need to use API functions.

44  { ... }
45  var
46    hSysMenu: HMENU;
47  begin
48    hSysMenu := getSystemMenu(Application.handle, false);
49    AppendMenu(hSysmenu, MF_STRING, $100, 'My Item');


The item IDs you use ($100 in this example) need to be multiples of 16, in hex 
notation that means the last digit is 0. Take care not to conflict with the 
predefined SC_ menu constants for the system menu. All of these have values above 
61000.

To get informed when the user selects your new item you need to hande the 
WM_SYSCOMMAND message send to the Application window. For this you attach a hook to 
it, using Application.HookMainWindow.

50  procedure TForm1.FormCreate(Sender: TObject);
51  var
52    hSysMenu: HMENU;
53  begin
54    hSysMenu := getSystemMenu(application.handle, false);
55    AppendMenu(hSysmenu, MF_STRING, $100, 'My Item');
56    Application.HookMainWindow(AppHook);
57  end;
58  
59  function Tform1.AppHook(var message: TMessage): Boolean;
60  begin
61    if (message.Msg = WM_SYSCOMMAND) and ((message.WParam and $FFF0) = $100) then
62    begin
63      Result := true;
64      ShowMessage('Hi, folks');
65    end
66    else
67      Result := false;
68  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