如:
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if MessageBox(handle,'关闭?','提示',MB_YESNO) = ID_NO then
CanClose := False;
end;
public
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
//处理WM_SYSCOMMAND消息.
end;
implementation
procedure TsinkDesktop.WMSysCommand;
begin
if (Msg.CmdType=SC_CLOSE) then begin//如果是Alt+F4或者按了X关闭.
showmessage('你要干啥');
end
else DefaultHandler(Msg);
end;
[red]窗体keyPreview设置程True;[/red]
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = vk_F4) and (ssAlt in Shift) then
begin
Key := 0;
ShowMessage('ok');
end;
end;
同意 独孤求败 兄 FormCloseQuery事件
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
//当真正需要关闭时作相应处理,否则弹出你的对话框
If 不需关闭 Then CanClose := False;
end;