Solved

multilevel system menu

Posted on 1999-01-21
3
184 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
ID: 1362742
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
ID: 1362743
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
ID: 1362744
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

22 Experts available now in Live!

Get 1:1 Help Now