Delphi在系統菜單中添加菜單項


unit dy219;

interface

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

type
TForm1 = class(TForm)
  procedure FormCreate(Sender: TObject);
private
  procedure sysmenu(var msg: twmmenuselect);message wm_syscommand;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
i := getsystemmenu(handle,false);
appendmenu(i,mf_separator,0,nil);
appendmenu(i,mf_string,100,'我的菜單(&E)');
end;

procedure TForm1.sysmenu(var msg: twmmenuselect);
begin
if msg.IDItem = 100 then
  showmessage('您選擇了自己添加的菜單!')
else
  inherited;
end;

end.
復制代碼

API函數

function GetSystemMenu(hWnd:HWND;bRevert:BOOL):HMENU;stdcall;

  參數說明:

  hWnd: 所要取得系統菜單句柄的目標窗口句柄。

  bRevert:是否修改原始菜單。

  返回一個HMENU型的菜單句柄。

  通過GetSystemMenu得到句柄后可以使用AppendMenu函數為系統菜單增加一個菜單項,該函數原型為:

function AppendMenu(hMenu:HMENU;uFlags,uIDNewItem:UNIT;lpNewItem:Pchar):BOOL;stdcall;

  參數說明:

  hMenu: 用GetSystemMenu函數得到的菜單句柄。

  uFlag,uIDNewItem:菜單唯一標志,彈出菜單唯一標志。

  lpNewItem:菜單的類型。

容易出現問題:

  缺少代碼 message wm_syscommand;這句代碼的主要作用是:A window receives this message when the user chooses a commond from the window menu.而如果注釋了inherited ,則所有系統菜單都不能用。

 

http://blog.csdn.net/zang141588761/article/details/51992368


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM