program Psysmenu;
uses
Forms,
Sysmenu in '\SYSMENU.PAS' {Form1};
{$R *.RES}
begin
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
unit Sysmenu;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes,
Graphics, Controls,Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
procedure user_sysmenu(var msg:twmmenuselect);
message wm_syscommand;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.user_sysmenu(var msg:TWMMENUSELECT);
begin
if msg.iditem=100 then
showmessage(' 響應系統菜單!')
{ 也 可 以setwindowpos()來實現處於最前端功能}
else
inherited; { 作缺省處理,必須調用這一過程}
end;
procedure TForm1.FormCreate(Sender: TObject);
var hmenu:integer;
begin
hmenu:=getsystemmenu(handle,false);
{獲取系統菜單句柄}
appendmenu(hmenu,MF_SEPARATOR,0,nil);
appendmenu(hmenu,MF_STRING,100,'加入系統菜單');
{加入用戶菜單}
end;
end.
//出錯的主要原因是:缺少一句代碼 message wm_syscommand;
//這句代碼的主要作用是:A window receives this message when the user chooses a commond from the window menu.
//而如果註釋了inherited ,則所有系統菜單都不能用。