I have some problems to connect a hook in my application.
Perhaps somebody has another suggestion:
I want to intercept ALT+F, CTRL+ALT+DEL, STRG+ESC, ALT+TAB and the Windows-Key.
At this point I can catch them, but I want to complete intercept all trys from the user to close my application or to switch to another program or the windows desktop. (There is an exit button, which the user has to use )
Back to captain hook... As I don't know another way yet, I am trying to get this to work.
It is from an example.
Code: Select all
HHOOK SMSMainframe::ghhookKB = NULL;
//---------------------------------------------------------------------------
void __stdcall SMSMainframe::SetHook(void)
{
ghhookKB = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)CheckKey,hinst, NULL);
}
//---------------------------------------------------------------------------
void __stdcall SMSMainframe::RemoveHook(void)
{
UnhookWindowsHookEx(ghhookKB);
}
//---------------------------------------------------------------------------
LRESULT CALLBACK SMSMainframe::CheckKey(int nCode, WORD wParam, LONG lParam)
{
bool bEatKeyStroke = false;
if (nCode == HC_ACTION)
{
switch (wParam)
{
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) lParam;
bEatKeyStroke =
((p->vkCode == VK_TAB) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
((p->vkCode == VK_ESCAPE) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
((p->vkCode == VK_ESCAPE) && ((GetKeyState(VK_CONTROL) & 0x8000) != 0));
break;
}
}
return(bEatKeyStroke ? 1 : CallNextHookEx(ghhookKB, nCode, wParam, lParam));
}
/*static HHOOK ghhookKB;
static void __stdcall SetHook(void);
static void __stdcall RemoveHook(void);*/
static LRESULT CALLBACK CheckKey(int, WORD,LONG);
My main problem is the SetHook Funktion from WinAPI. It wants a pointer to an instance (hinst). I don't get the solution...
ghhookKB = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)CheckKey,hinst, NULL);
The Funktions are declared in the main window class. SMSMAinframe. It's a child of wxFrame.
Thank your for your help and hints.