您的位置:首页 > 编程语言 > Delphi

Delphi如何获取QQ2010聊天窗口句柄?

2011-02-25 15:35 477 查看
unit   HKProc;

interface

uses
Windows,   Messages,Dialogs,iniFiles,SysUtils;

var
hNextHookProc:   HHook;
procSaveExit:   Pointer;

function   CBTProc(iCode:   Integer;   wParam:   WPARAM;   lParam:   LPARAM):   LRESULT;   stdcall;
function   EnableHotKeyHook:   BOOL;   export;
function   DisableHotKeyHook:   BOOL;   export;

implementation

function   CBTProc(iCode:   Integer;   wParam:   WPARAM;   lParam:   LPARAM):   LRESULT;   stdcall;
var
p:   PCBTActivateStruct;
begin
result:=   0;
If   iCode <0   Then
begin
Result   :=   CallNextHookEx(hNextHookProc,   iCode,   wParam,   lParam);
Exit;
end
else
begin
If   iCode   =   HCBT_ACTIVATE   then
begin
p:=   PCBTActivateStruct(lParam);
if   (p.hWndActive   =   findwindow( '#32770 ',nil))   then   showmessage( 'lkjl ');
end;
end;
end;

function   EnableHotKeyHook:   BOOL;   export;
begin
Result   :=   False;
if   hNextHookProc   <>   0   then   Exit;
hNextHookProc   :=   SetWindowsHookEx(WH_CBT,CBTProc,HInstance,0);
Result   :=   hNextHookProc   <>   0;
end;

function   DisableHotKeyHook:   BOOL;   export;
begin
if   hNextHookProc   <>   0   then
begin
UnhookWindowshookEx(hNextHookProc);
hNextHookProc   :=   0;
end;
Result   :=   hNextHookProc   =   0;
end;

end.
If   iCode   =   HCBT_ACTIVATE   then
begin
p:=   PCBTActivateStruct(lParam);
p.hWndActive//就是激活窗口的句柄。findwindow( '#32770 ',nil)返回的是QQ聊天窗口的句柄
end;

http://zhidao.baidu.com/question/168272170.html?fr=qrl&cid=868&index=1&fr2=query
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: