有关hook的问题 ( 积分: 50 )

  • 主题发起人 主题发起人 bin2000
  • 开始时间 开始时间
B

bin2000

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