需要捕捉WM_SYSCOMMAND消息,然后作出判断。
procedure WMSysCommand(var Msg: TMessage);
begin
if Msg.wParam <> SC_CLOSE then
inherited;
end;
procedure WMSysCommand(var Msg: TMessage);
begin
if Msg.wParam <> SC_CLOSE then
inherited;
end;
解决方案 »
- 如何引用DLL中的相关参数表,控件如EDIT,LABEL等之类的控件
- 急,急,急,火烧眉毛!
- 含有中文的字符串 如何统计字符个数?
- 急,急,急,求在dbgrid每行数据前有一个复选框控件
- Richedit是否存在bug?
- DELPHI转到JB上?
- 散分答谢CSDN朋友的关心和帮助,同时广交csdn的朋友!
- 急!求助!
- 怎样给Tcollectionitem类加Popupmenu?
- 送分了,TChart、TDBChart是做棒图的控件,做网站的ISAPI中如何用它?
- 谁可以提供Delphi 5的serial和auth key
- 我最近在写一个聊天程序,请问有什么好办法来打包数据,并用sendtext发出去?
建立一个:Action,将它的快捷键(ShortCut)定义为 Alt+F4,在其代码处写一个空行。
这样用户一但去按 Alt+F4,程序就去执行这一段空的代码而不去执行系统定义的关闭窗口。
从而实现屏蔽的目的。
Shift: TShiftState);
begin
if key=115 then key:=0
end;一定可以,试过了。给分噢
我试了一下你的代码,发现只是新建一个Form(空白的),你的方法可以用,但是一旦在上面添加了一个控件(什么控件都行,我用的是button)后,就不行了,窗体还是被Alt+F4给关了
A better way to disable ALT+F4 to prevent form closing
Undertitle: Catch the WM_SYSCOMMAND message
Category: VCL-General
Uploader: Chen Jiangyong
Question: How can I disable the Alt+F4 key combination to keep my form
from closing? (A better way)
Answer: After I read the article about Peter Lieber's Disabling ALT-F4 to prevent form closing, I think I know a better way to resolve it.
In Windows, when you press ALT+F4 in a form, a WM_SYSCOMMAND will occur. (For more about WM_SYSCOMMAND see MSDN or other win32 help.) So if you catch the WM_SYSCOMMAND message it is easy to prevent form closing.
Example:TForm1 = class(TForm)
{...}
private
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
{...}
end;procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
begin
if Msg.CmdType <> SC_CLOSE then // Prevent ALT+F4
inherited;
end;Gook luck!