DelphiFAQ Home Search:

Add menu items to the system menu

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

The following form shows how to add your own menu items to the form's
system menu and where to process them:

unit Unit1;

interface

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

type
  TForm1 = class (TForm)
    procedure FormCreate (Sender: TObject);
  private
  { private declarations }
    public
    procedure WinMsg (var Msg: TMsg; var Handled: Boolean);
    { This is what handles the messages }
    procedure DOWHATEVER;
    { procedure to do whatever }

  end;

var
  Form1 : TForm1;

implementation

{$R *.DFM}
const
  ItemId = 99;

{the ID number for your menu item--can be anything} 
procedure TForm1.WinMsg (var Msg: TMsg; var Handled: Boolean); 
begin 
  if Msg.message = WM_SYSCOMMAND then 
    {if the message is a system one...} 
    if Msg.WPARAM = ItemId then 
      DOWHATEVER 
  {then check if its parameter is your Menu items ID}  
end; 


procedure TForm1.FormCreate (Sender: TObject); 
begin 
  Application.OnMessage := WinMsg; 
  {tell your app that 'winmsg' is the application message handler} 
  AppendMenu (GetSystemMenu (Form1.Handle, False), 
    MF_SEPARATOR, 0, ''); 
  {Add a seperator bar to form1} 
  AppendMenu (GetSystemMenu (Form1.Handle, False), 
    MF_BYPOSITION, ItemId, '&New Item'); 
  {add your menu item to form1} 
  AppendMenu (GetSystemMenu (Application.Handle, False), 
    MF_SEPARATOR, 0, ''); 
  {Add a seperator bar to the application system menu(used }
  {when app is minimized)} 
  AppendMenu (GetSystemMenu (Application.Handle, False), 
    MF_BYPOSITION, ItemId, '&New Item') 
  {add your menu itemto the application system menu(used when app is minimized)} 
  
  { for more information on the AppendMenu and GetSystemMenu see online help} 
end; 


procedure TForm2.DOWHATEVER; 
begin 
  { add whatever you want to this procedure } 
end; 

end.

Comments:

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.