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

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
posted @ 2011-10-25 09:10  bingege  阅读(670)  评论(0编辑  收藏  举报