Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetWindowsHookEx with type WH_CBT

Status
Not open for further replies.

titanandrews

Programmer
Feb 27, 2003
130
0
0
US
Hi All,

Has anyone ever set a global hook with SetWindowsHookEx and tried to "listen" for windows getting focus with any success? I have installed the following callback function for the WH_CBT function type. The hook is installed fine with no errors, but the only code I am getting inside the function is HCBT_CLICKSKIPPED a few times and then nothing. A google search has turned up a lot of this same scenario, but no one seemed to ever get a resolution. I was hoping someone here has had this issue before and knows what the problem is.

Many thanks in advance!!!

-B

Code:
LRESULT CALLBACK FocusProc(int nCode,WPARAM wParam,LPARAM lParam)
{        
    if(nCode < 0)
        return ::CallNextHookEx(*_pHook,nCode,wParam,lParam);


    char buffer[20];
    _itoa_s(nCode,buffer,10);
    OutputDebugString(buffer);
    if(nCode == HCBT_SETFOCUS)
    {
        HWND hWnd = ( HWND ) wParam;        
        TCHAR buf[256];
        ::GetWindowText(hWnd,buf,256);        
        //cout << "Focus" << buf << endl;
        ::OutputDebugString("Focus"); 
    }

    return ::CallNextHookEx(*_pHook,nCode,wParam,lParam);    
}
 
As far as I know (from MSDN) CBTProc hook function must be:
1... defined in a DLL
2... return 0 to allow op, or 1 to prevent it
Are you sure the last (return) stmt with hook chain call is OK?
 
Thanks for your thoughts, ArkM.
1) Yes, it does have to be in a dll, and it is.
2) I checked the return statement and I am getting 0 for every call.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top