procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState); begin if (ssAlt in shift)and(key=115) then key:=0; end; ------------------------------------------------------------------------------------------------------------ type TForm1 = class(TForm)后,Private前面写: procedure SysCommand(var msg:TWMSysCommand);message WM_SysCommand;实现; procedure TForm1.SysCommand(var msg: TWMSysCommand); begin if msg.CmdType = SC_CLOSE then begin msg.cmdtype:= SC_DEFAULT; Hide; end; inherited; end; ------------------------------------------------------------------------------------------------------------- TForm1 = class ... private procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND; ...end;procedure TForm1.WMSysCommand(var Msg: TWMSysCommand); begin if Msg.CmdType <> SC_CLOSE then inherited end;
another:屏蔽ctrl+alt+delunit start;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;Const RSP_SIMPLE_SERVICE = 1; Const RSP_UNREGISTER_SERVICE = 0;type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); private { Private declarations } public { Public declarations } end;var Form1: TForm1; Function GetCurrentProcessId():Longint;stdcall;far;external 'kernel32'; Function GetCurrentProcess():Longint;stdcall;far;external 'kernel32'; Function RegisterServiceProcess(dwProcessID:Longint;dwType:Longint):Longint;stdcall;far;external 'kernel32'; implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject); var pid:longint; begin pid:=GetCurrentProcessId(); //得到当前进程ID RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE);//把本程序注册为service end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); var pid:Longint; begin pid:=GetCurrentProcessId(); RegisterServiceProcess(pid,RSP_UNREGISTER_SERVICE); end; end.//调试过了,在win98+Delphi5通过!
begin
if (ssAlt in shift)and(key=115) then key:=0;
end;
------------------------------------------------------------------------------------------------------------
type
TForm1 = class(TForm)后,Private前面写:
procedure SysCommand(var msg:TWMSysCommand);message WM_SysCommand;实现;
procedure TForm1.SysCommand(var msg: TWMSysCommand);
begin
if msg.CmdType = SC_CLOSE then
begin
msg.cmdtype:= SC_DEFAULT;
Hide;
end;
inherited;
end;
-------------------------------------------------------------------------------------------------------------
TForm1 = class
...
private
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
...end;procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
begin
if Msg.CmdType <> SC_CLOSE then
inherited
end;
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;Const RSP_SIMPLE_SERVICE = 1;
Const RSP_UNREGISTER_SERVICE = 0;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
Function GetCurrentProcessId():Longint;stdcall;far;external 'kernel32';
Function GetCurrentProcess():Longint;stdcall;far;external 'kernel32';
Function RegisterServiceProcess(dwProcessID:Longint;dwType:Longint):Longint;stdcall;far;external 'kernel32';
implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
var
pid:longint;
begin
pid:=GetCurrentProcessId(); //得到当前进程ID
RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE);//把本程序注册为service
end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
pid:Longint;
begin
pid:=GetCurrentProcessId();
RegisterServiceProcess(pid,RSP_UNREGISTER_SERVICE);
end;
end.//调试过了,在win98+Delphi5通过!
GetMenuItemCoun
DeleteMenu
procedure WMHotKey(var Message: TWMHOTKEY); message WM_HOTKEY;
....
procedure TForm1.FormCreate(Sender: TObject);
begin
RegisterHotKey(Handle, GlobalAddAtom('hotkey'), mod_alt, vk_F4);
end;
...
procedure TForm1.WMHotKey(var Message: TWMHOTKEY);
begin
//定义热键事件
end;
...
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnregisterHotKey(Handle, GlobalAddAtom('hotkey'));
end;
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
ComboBox1: TComboBox;
RadioGroup1: TRadioGroup;
GroupBox1: TGroupBox;
Label2: TLabel;
Edit1: TEdit;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
Button1: TButton;
Button2: TButton;
ProgressBar1: TProgressBar;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
HotKeyId: Integer;
procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY; public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}
//处理消息过程
procedure TForm1.HotKeyDown(var Msg: Tmessage);
begin
if (Msg.LparamLo = Mod_Alt) And (Msg.LParamHi = VK_F4) then
begin
showmessage('OK');
end;
end;procedure TForm1.FormCreate(Sender: TObject);
var
total:real;
temp_title:string;
title:array [0..127] of char;
found: HWND;
reghotkey:boolean;
begin
//注册alt+f4热键
HotKeyId := GlobalAddAtom('HotKey') - $C000;
if RegisterHotKey(Handle, hotkeyid, Mod_Alt, VK_F4) then
showmessage('reg suc');
//防止多次运行
StrPCopy(title,Application.Title);
temp_title:=Application.Title;
Application.Title:='temp';
found:=findwindow(nil,title);
Application.Title:=temp_title;
if found<>0 then begin
ShowWindow(Found, SW_RESTORE);
Application.Terminate
end;
//屏蔽其它系统热键和开始菜单
SystemParametersInfo(Spi_screensaverrunning,1,nil,0);
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
EnableWindow(FindWindowEx(FindWindow('Shell_TrayWnd', nil),
0,'Button',nil),false);
RadioGroup1.ItemIndex:=0;
//取C盘容量,并在combobox里显示出来
total:=DiskSize(3)/1024/1024;
ComboBox1.Text:=format('%.1f',[total])+' Mb';
ComboBox1.Items.Add(ComboBox1.Text);
end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
{ if RadioGroup1.ItemIndex<>1 then
CanClose:=false; }
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//恢复被屏蔽的热键
SystemParametersInfo(Spi_screensaverrunning,0,nil,0);
EnableWindow(FindWindowEx(FindWindow('Shell_TrayWnd', nil),
0,'Button',nil),true);
unregisterhotkey(handle,hotkeyid);
DeleteAtom(HotKeyid);
end;end.
SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs;type
TMainForm = class(TForm)
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;var
MainForm: TMainForm;implementation{$R *.DFM}procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if MessageDlg('是否关闭窗体', mtConfirmation, mbYesNoCancel, 0) = mrYes then
CanClose := True
else
CanClose := false;
end;end.