unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure SystemMenuCommand(var Msg:TWMMENUSELECT);
message WM_SysCommand;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
// 设置系统菜单
AppendMenu(GetSystemMenu(Handle,False),MF_SEPARATOR,0,'');
AppendMenu(GetSystemMenu(Handle,False),MF_STRING,200,'前端显示(&A)');
end;
procedure TForm1.SystemMenuCommand(var Msg:TWMMENUSELECT);
begin
if Msg.IDItem = 200 then
begin
if Form1.FormStyle = fsNormal then
begin
// 将窗体设置为总在前端显示
Form1.FormStyle := fsStayOnTop;
// 重新设置系统菜单
AppendMenu(GetSystemMenu(Handle,False),MF_SEPARATOR,0,'');
AppendMenu(GetSystemMenu(Handle,False),MF_STRING,200,'前端显示(&A)');
// 在新添加的菜单项前增加一个选中标志
ModifyMenu(GetSystemMenu(Handle,False),200,MF_CHECKED,200,'前端显示(&A)');
end
else
begin
// 将窗体设置为普通模式
Form1.FormStyle := fsNormal;
// 重新设置系统菜单
AppendMenu(GetSystemMenu(Handle,False),MF_SEPARATOR,0,'');
AppendMenu(GetSystemMenu(Handle,False),MF_STRING,200,'前端显示(&A)');
end;
end;
inherited;
end;
end.