I want to make my window the active window as soon as the mouse passes over it. I tried using SetActiveWindow() and SetForegroundWindow() but those functions didn't do it, they just made the taskbar entry flash. I then did this:
Code:
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_MOUSEMOVE:
if (hwnd!=GetActiveWindow())
{
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,NULL, NULL);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,NULL, NULL);
}
break;
default:
break;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
}
And it works fine. Is there a more efficient way to do it? Maybe I'm not using SetActiveWindow() correctly?