Link to home
Start Free TrialLog in
Avatar of jamoville
jamovilleFlag for Afghanistan

asked on

SetWindowsHookEx - focus on a particular application

I'm using the setwindowshookex function with the WH_CBT parameter.  The function calles a DLL that I created to determine several things, including if a window has been created. How would I specify this application to work with only one specific application?  For instance,  how would I make this program work and catch messages from only microsoft word?
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jamoville

ASKER

Were would you use this function.  Would it be in the getwindowshookex function of my application, or in the DLL.  I would think it would be in the hookex function to get the threadid.
Usually you'd call this from within the hook procedure to filter the messages. Example (though it is an excerpt from an WH_GETMESSAGE hook):
LRESULT CALLBACK HookProc   (   int     nCode,  // hook code
                                WPARAM  wParam, // removal flag
                                LPARAM  lParam  // address of structure with message
                            )
{
    PMSG    pmsg    =   ( PMSG) lParam;

    if  (       0   >   nCode  
            ||  PM_NOREMOVE ==  wParam  
            ||  !strstr (   GetCommandLine  (), "winword.exe") // bail out if not Word...
        )
        {
            return  (   CallNextHookEx  (   g_hhk,
                                            nCode,
                                            wParam,
                                            lParam
                                        )
                    );
        }

    //....
}