精
精灵魔
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br>interface<br>uses<br>Windows, Messages, Forms, Dialogs, Classes, Controls, StdCtrls;<br>type<br> TForm1 = class(TForm)<br> procedure FormCreate(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> private<br> id1,id2: Integer;<br> procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY;<br>{ Privat-Declarations}<br> public<br>{ Public-Declarations}<br> end;<br>var<br> Form1 : TForm1;<br>implementation<br>{$R *.DFM}<br><br>procedure TForm1.WMHotKey (var Msg : TWMHotKey);<br>var<br> Wnd:HWND;<br>begin<br> if msg.HotKey = id1 then<br> begin<br> Wnd:=FindWindow('Notepad', nil); //这样会把记事本窗口给关闭了<br> PostMessage(Wnd,WM_CLOSE,0,0);<br> end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>Const<br> MOD_ALT = 1; <br> MOD_CONTROL = 2;<br> MOD_SHIFT = 4;<br>begin<br> Application.Title:='';<br> if GlobalFindAtom('MyHotkey1') = 0 then<br> begin<br> id1:=GlobalAddAtom('MyHotkey1');<br> RegisterHotKey(handle,id1,MOD_CONTROL+MOD_Alt+MOD_SHIFT,0);<br> end;<br>end;<br><br>{退出时释放全局热键}<br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> UnRegisterHotKey(handle,id1);<br> GlobalDeleteAtom(id1);<br>end;<br>end.<br>源程序如上,此代码只能在释放Ctrl+Alt+Shift时关闭记事本.那到底怎么修改才能按下Ctrl+Alt+Shift马上关闭记事本.