我改成这样也不行啊!哪里错了? procedure TForm1.WMSYSCOMMAND(var Msg: TWMSYSCOMMAND); begin if Msg.Msg = SC_CLOSE then begin if Application.MessageBox('你要退出吗?', '确定', MB_OKCANCEL + MB_ICONERROR) = idok then Inherited else Abort; end; end;
procedure TForm1.WMSYSCOMMAND(var Msg: TWMSYSCOMMAND); begin if Msg.wParam = SC_CLOSE then begin if Application.MessageBox('你要退出吗?', '确定', MB_OKCANCEL + MB_ICONERROR) = idok then Inherited else Abort; end; end;
private { Private declarations } procedure WMSysCommanda(var Msg: TMsg; var Handled: Boolean); ...procedure TfrmFir.FormCreate(Sender: TObject); begin Application.OnMessage := WMSysCommanda; ... end; ... procedure TfrmFir.WMSysCommanda(var Msg: TMsg; var Handled: Boolean); begin if Msg.wParam = SC_CLOSE then begin if Application.MessageBox('你要退出吗?', '确定', MB_OKCANCEL + MB_ICONERROR) = idok then Inherited else Abort; end; end;
if Application.MessageBox('你要退出吗?', '确定', MB_OKCANCEL + MB_ICONERROR) = IDOK then
Inherited
else
Abort;
WM_SYSCOMMAND当wParam = SC_CLOSE就是 窗口关闭
CanClose := true
else
CanClose := false;
procedure TForm1.WMSYSCOMMAND(var Msg: TWMSYSCOMMAND);
begin
if Msg.Msg = SC_CLOSE then
begin
if Application.MessageBox('你要退出吗?', '确定', MB_OKCANCEL + MB_ICONERROR) = idok then
Inherited
else
Abort;
end;
end;
begin
if Msg.wParam = SC_CLOSE then
begin
if Application.MessageBox('你要退出吗?', '确定', MB_OKCANCEL + MB_ICONERROR) = idok then
Inherited
else
Abort;
end;
end;
{ Private declarations }
procedure WMSysCommanda(var Msg: TMsg; var Handled: Boolean);
...procedure TfrmFir.FormCreate(Sender: TObject);
begin
Application.OnMessage := WMSysCommanda;
...
end;
...
procedure TfrmFir.WMSysCommanda(var Msg: TMsg; var Handled: Boolean);
begin
if Msg.wParam = SC_CLOSE then
begin
if Application.MessageBox('你要退出吗?', '确定', MB_OKCANCEL + MB_ICONERROR) = idok then
Inherited
else
Abort;
end;
end;
一个发送向Application, 而一个是发向Form...可以通过对Application的消息处理实现 .