R
ralfa
Unregistered / Unconfirmed
GUEST, unregistred user!
我查了好多资料和在这里翻查了好久的帖子,但是还是无法做的出来<br><br>我要做的其实以前好多帖子都提出过了的 ,但是都没确切的代码可以提供参考<br>就是 如果我需要监视 系统窗口的 创建/焦点变更/关闭 一类事件 该如何写呢<br>下面是我写的测试DLL 目的是取得其他激活的窗口的句柄,但是好象失败了,来来去去都是在同一返回值;<br>library ProjectDllTest;<br>uses<br> SysUtils,<br> Windows,<br> Classes,<br> IniFiles,<br> Messages;<br><br>{$R *.res}<br><br>var<br> CBTHandle: HHOOK;//hook<br> masin:integer;//回传变量<br> master_masin:integer;<br><br> //------------------<br>function sets(masters:integer) :integer;stdcall;export;<br>begin<br>master_masin:=masters;<br>end;<br> function gets():integer;stdcall;export;<br> begin<br><br> result:=masin;<br><br> end;<br><br> //--------------------------- CBT Hook test ---------------------------<br>// CBT(computer-based training )全局钩子测试函数<br>function CBTProc(nCode: Integer;wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;<br>var now_masin:integer;<br>begin<br> if(nCode = HCBT_ACTIVATE) then<br> begin<br> now_masin:=GetForegroundWindow;<br> if(now_masin<>master_masin) then<br> begin<br> masin:=now_masin;<br> end;<br> end;<br> Result := CallNextHookEx(CBTHandle,nCode,wParam,lParam);<br>end;<br><br>// 设置CBT全局钩子<br>function EnableCBTHook(): Boolean; stdcall; export;<br>begin<br><br> cbtHandle := SetWindowsHookEx(WH_cbt,@cbtProc,hInstance,0);<br> if( cbtHandle = 0) then Result := False<br> else Result := True;<br>end;<br><br>//取消 CBT全局钩子<br>function DisableCBTHook(): Boolean; stdcall; export;<br>begin<br> if( cbtHandle <> 0) then UnhookWindowsHookEx(cbtHandle);<br> Result := True;<br>end;<br><br>exports<br> EnableCBTHook,DisableCBTHook ,gets,sets;<br>end.