How to active SetWindowsHookEx after unlock screen?

  • Thread starter Thread starter TuyenTk
  • Start date Start date
T

TuyenTk

Guest
Im writing an app that use global hook. Any thing is ok. But after lock windows (Windows + L) then login again, my hook function dont work any more.

That I want after I login again, my hook function continue work. How to do that? Thank you!

HHOOK _k_hook;
HWND hwnd;


void tuyen_Reg(bool mode)
{
const int tuyen_HotKey_Active = 1991;
if (mode)
{
RegisterHotKey(hwnd,tuyen_HotKey_Active,MOD_CONTROL | MOD_NOREPEAT,32);
_k_hook = SetWindowsHookExA(13, k_Callback,NULL,0);
}
else
{
UnregisterHotKey(hwnd,tuyen_HotKey_Active);
UnhookWindowsHookEx(_k_hook);
}
}

LRESULT __stdcall k_Callback(int nCode, WPARAM wParam, LPARAM lParam)
{
CallNextHookEx(_k_hook, nCode, wParam, lParam);
if (nCode >= 0)
{
//...
}
return 0;
}


LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
{
switch( message )
{
case WM_HOTKEY:

// ********** Im trying rehook: **********

// ********** But it doesnt work: **********
Beep (500, 100);
tuyen_Reg(false);
tuyen_Reg(true);
break;
case WM_DESTROY:
PostQuitMessage( 0 ) ;
break;
}
return DefWindowProcA( hwnd, message, wparam, lparam );
}

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow )
{
//...
tuyen_Reg(true);

MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}

Continue reading...
 
Back
Top