Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i edit the application menu!

Status
Not open for further replies.

MirceaVleju

Programmer
Oct 10, 2003
32
RO
How can i edit the application menu! (The one with restore,size,menu,etc)
 
The following bit of code ought to do it.
Note: Change the items in the popupmenu to suit your needs.
Code:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  AppEvnts, ExtCtrls, Menus;

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    Item1: TMenuItem;
    Item2: TMenuItem;
    Item3: TMenuItem;
    Item4: TMenuItem;
    procedure FormCreate(Sender: TObject);
  private
    procedure OnMessage(var Msg: tagMSG;
      var Handled: Boolean);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

const
  mnuBreak = 149; //any numbers
  mnuMyItem = 150;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
 //catch menu click for my item
 //Note: Delphi 5 users can use the new TApplicaton component, use the OnMessage event
 Application.OnMessage:= OnMessage;

 //add seperator at end
 AppendMenu(GetSystemMenu(Form1.Handle, False),
           MF_SEPARATOR,
           mnuBreak,
           '');

 //now add my item at end
 AppendMenu(GetSystemMenu(Form1.Handle, False),
           MF_STRING,
           mnuMyItem,
           '&My Item');

 //last add submenu item and assign popupmenu handle
 AppendMenu(GetSystemMenu(Form1.Handle, False),
           MF_POPUP,
           PopupMenu1.Handle,
           '&Sub Menu');

end;

procedure TForm1.OnMessage(var Msg: tagMSG;
  var Handled: Boolean);
begin
 //look in win32.hlp for more information; WM_SYSCOMMAND
 if Msg.Message = WM_SYSCOMMAND then
   begin
   if Msg.WParam = mnuMyItem then //i guess the handle we assigned
     ShowMessage('Your handler here');
   end;

end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top