jamoville
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
)
);
}
//....
}
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
)
);
}
//....
}
ASKER