B
bin2000
Unregistered / Unconfirmed
GUEST, unregistred user!
以下是我编的一个DLL库,用途是在任何情况下按下F12后,就会弹出一个窗体(测试通过)。<br>目前生成窗体的owner是Application,我想让它的owner是任意一个窗口,比如说<br>记事本,该怎么写程序?<br><br>library hooktest;<br><br>uses<br> SysUtils,<br> Windows,<br> Messages,<br> Dialogs,<br> Classes,<br> Forms,<br> Unit1 in 'Unit1.pas' {Form1};<br><br>{$R *.res}<br><br>var<br> g_hhook: HHook;<br> Form1: TForm1;<br><br><br>function KeyboardProc(nCode:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>var<br> bKeyUp: Integer;<br> fHwnd: THandle;<br> buf: pchar;<br>begin<br> bKeyUp := lParam and ( 1 shl 31 );<br> if (bKeyUp<>0) and (wParam = VK_F12) and (nCode = HC_ACTION) then<br> begin<br> if Form1 = nil then<br> begin<br> Form1 := TForm1.Create(Application);<br> Form1.Show;<br> end<br> else begin<br> if Form1.Visible then Form1.Hide<br> else Form1.Show;<br> end;<br> end;<br> Result := CallNextHookEx(g_hhook, nCode, wParam ,lParam);<br>end;<br><br>function InstallHook:Boolean;stdcall;<br>begin<br> Result := False;<br> if g_hhook = 0 then<br> begin<br> g_hhook := SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, HInstance, 0);<br> if g_hhook = 0 then<br> Result := False<br> else<br> Result := True;<br> end;<br>end;<br><br>function UnInstallHook:Boolean;stdcall;<br>begin<br> if Form1 <> nil then Form1.Free;<br> Result := UnhookWindowsHookEx(g_hhook);<br>end;<br><br>exports <br> InstallHook,<br> UnInstallHook;<br><br>begin<br>end.