Solved

multilevel system menu

Posted on 1999-01-21
3
181 Views
Last Modified: 2010-04-06
How can I add a multilevel menu to my app system menu?
I feel this should be done somehow with appendmenu(), but how?
0
Comment
Question by:duke_n
  • 2
3 Comments
 
LVL 17

Expert Comment

by:inthe
Comment Utility
i found this one on the net a while back ,hope you can understand it ok:

 PURPOSE:     Demo program.  Shows how to add items to system menu of form and application.  The system menus are           different because the Application effectively puts a             wrapper around the forms.

  CAVEATS:     The IDs for new menu items must be multiples of 16 (or in hex, have the form $XXX0).  This is because Windows           uses the lower 4 bits of WParam in the WM_SYSCOMMAND               message for internal purposes, so you have to mask them
out if you trap this message and check WParam for your
ID. To check if a menu ID already exists, use         GetMenuState( hMenu, ItemID, MY_BYCOMMAND);
 This returns -1 if an item with the passed ID does NOT
   already exist. }

unit Sysmenu1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    Procedure AppMessage( var msg:TMsg; var Handled : Boolean);
  public
  end;

var
  Form1: TForm1;

implementation

{ Add an item to the system menu and the form menu. }
procedure TForm1.FormCreate(Sender: TObject);
var
  FormSysMenu, AppSysMenu : THandle;
begin
  AppSysMenu := GetSystemMenu(Application.Handle,False);
  AppendMenu(AppSysMenu,mf_Separator,0,'');
  AppendMenu(AppSysMenu,mf_Enabled,$E010,'App Menu Item');

  FormSysMenu := GetSystemMenu(Form1.Handle,False);
  AppendMenu(FormSysMenu,mf_Separator,0,'');
  AppendMenu(FormSysMenu,mf_Enabled,$E020,'Form Menu Item');

  Application.OnMessage := AppMessage;
end;

{ Intercept Windows messages & find those from our new menu items }
Procedure TForm1.AppMessage( var msg:TMsg; var Handled : Boolean);
begin
  if msg.WParam = $E010 then begin
     Handled := True;
     MessageBox(Handle,'From Application Menu','Menu Result',mb_OK);
     end;

  if msg.WParam = $E020 then begin
     Handled := True;
     MessageBox(Handle,'From Form Menu','Menu Result',mb_OK);
     end;
end;

end.
Regards Barry

0
 
LVL 1

Author Comment

by:duke_n
Comment Utility
I know how to add items to system menu!!!

I wanted to add'em to make a MULTILEVEL, CASCADING(like start>programs menu, or explorer's file>new menu) !!!!!
0
 
LVL 17

Accepted Solution

by:
inthe earned 20 total points
Comment Utility
hi duke_n
god this took me ages to work out but finally i cracked it.hop it's what you were after,you need to create a popup first then append away
Regards Barry

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
       Procedure AppMessage( var msg:TMsg; var Handled : Boolean);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
Procedure TForm1.AppMessage( var msg:TMsg; var Handled : Boolean);
begin
  if msg.WParam = $E010 then begin
     Handled := True;
     MessageBox(Handle,'From Application Menu','Menu Result',mb_OK);
     end;

  if msg.WParam = $E020 then begin
     Handled := True;
     MessageBox(Handle,'From Form Menu','Menu Result',mb_OK);
     end;
 
  if msg.WParam = $E060 then begin
     Handled := True;
     Showmessage ('Hello how are you');
      end;
end;
procedure TForm1.FormCreate(Sender: TObject);

var
  FormSysMenu, AppSysMenu : THandle;
  MenuItemInfo:TMenuItemInfo;
  hPopup : HMenu;
  begin
  AppSysMenu := GetSystemMenu(Application.Handle,False);
   AppendMenu(AppSysMenu,mf_Separator,0,'');
  AppendMenu(AppSysMenu,mf_ENABLED,$E010,'App Menu Item');
  hPopup := CreatePopupMenu;
  AppendMenu(appsysmenu,MF_POPUP,hPopup,'&Test');
  FormSysMenu := GetSystemMenu(Form1.Handle,False);
  AppendMenu(FormSysMenu,mf_Separator,0,'');
  AppendMenu(FormSysMenu,mf_Enabled,$E020,'Form Menu Item');
  AppendMenu(Formsysmenu,MF_POPUP,hPopup,'&Test');
  Appendmenu(hpopup,mf_enabled,$E030,'&Here');
  Appendmenu(hpopup,mf_enabled,$E040,'&Is');
  Appendmenu(hpopup,mf_enabled,$E050,'&A Pop-up');
  Appendmenu(hpopup,mf_enabled,$E060,'&Menu');
  Application.OnMessage := AppMessage;
end;

end.




0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now