Q
qet006
Unregistered / Unconfirmed
GUEST, unregistred user!
下边是简单网游加血的DEMO<br>它的运行程序能很好的运行,但这个文件不能编译,<br>函数KeyboardHookProc在Application.Handle:= GetForegroundWindow处不过<br>我在USER中加入Forms可以通过,但运行时没有出现窗口<br>unit drProc;<br><br>interface<br><br>uses<br> Windows, SysUtils;<br><br>var<br> hNextHookProc: HHook;<br> procSaveExit: Pointer;<br><br>function KeyboardHookProc(code: Integer; wparam: WPARAM;<br> lparam: LPARAM): LRESULT stdcall; export;<br>function CreateKeyboardHook: BOOL; stdcall; export;<br>function DestroyKeyboardHook: BOOL; stdcall; export;<br>procedure KeyboardHookExit;<br><br>implementation<br><br>var<br> GameSwitch: Word; //程序热键<br><br>function KeyboardHookProc(code: Integer; wparam: WPARAM;<br> lparam: LPARAM): LRESULT;<br>const<br> _KeyProcessMask = $80000000;<br>begin<br> Result := 0;<br> if code < 0 then<br> begin<br> Result := Windows.CallNextHookEx(hNextHookProc, code, wparam, lparam);<br> Exit;<br> end;<br> if ((lparam and _KeyProcessMask) = 0) and (wparam = GameSwitch) then<br> begin<br> Application.Handle:= GetForegroundWindow; //返回当前窗口句柄<br><br> Result := 1;<br> end;<br>end;<br><br>function CreateKeyboardHook: BOOL;<br>begin<br> Result := false;<br> if hNextHookProc <> 0 then<br> exit;<br> hNextHookProc := Windows.SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc,<br> hInstance, 0);<br> Result := hNextHookProc <> 0;<br>end;<br><br>function DestroyKeyboardHook: BOOL;<br>begin<br> if hNextHookProc <> 0 then<br> begin<br> Windows.UnhookWindowsHookEx(hNextHookProc);<br> hNextHookProc := 0;<br> end;<br> Result := hNextHookProc = 0;<br>end;<br><br>procedure KeyboardHookExit;<br>begin<br> if hNextHookProc <> 0 then<br> DestroyKeyboardHook;<br> ExitProc := procSaveExit;<br>end;<br><br>Initialization<br> GameSwitch := VK_HOME;<br><br>end.