unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
// 我的消息过滤器
procedure OnAppMessage(var Msg: TMsg; var Handled: Boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
const
My_SimpleCMD1 = WM_USER + 1; // 定义三个用户消息,用来处理菜单项被点击
// 时相应的动作
My_SimpleCMD2 = WM_USER + 2;
My_SimpleCMD3 = WM_USER + 3;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := OnAppMessage; //定义自己的消息处理过程
//定义了提交、反馈、处理三个菜单项
AppendMenu(GetSystemMenu(Application.Handle, FALSE),MF_STRING,
My_SimpleCMD1,'提交');
AppendMenu(GetSystemMenu(Application.Handle, FALSE),MF_STRING,
My_SimpleCMD2,'反馈');
AppendMenu(GetSystemMenu(Application.Handle, FALSE),MF_SEPARATOR, 0, '-'); // 定义一分割线
AppendMenu(GetSystemMenu(Application.Handle, FALSE),MF_STRING,My_SimpleCMD3,'处理');
end;
procedure TForm1.OnAppMessage(var Msg: TMsg; var Handled: Boolean);
begin
// 定制自己的消息处理过程
if (Msg.message = WM_SYSCOMMAND) and (Msg.wParam = My_SimpleCMD1) then
begin
ShowMessage('正在提交...');
Handled := True;
//...
end;
if (Msg.message = WM_SYSCOMMAND) and (Msg.wParam = My_SimpleCMD2) then
begin
ShowMessage('正在反馈...');
Handled := True;
end;
if (Msg.message = WM_SYSCOMMAND) and (Msg.wParam = My_SimpleCMD3) then
begin
ShowMessage('正在处理...');
Handled := True;
end;
end;
end.