Is there Windows system event on active window changed? Is there Windows system event on active window changed? windows windows

Is there Windows system event on active window changed?


Yes, you can use SetWinEventHook function.

hEvent = SetWinEventHook(EVENT_SYSTEM_FOREGROUND ,     EVENT_SYSTEM_FOREGROUND , NULL,     WinEventProcCallback, 0, 0,     WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);.......VOID CALLBACK WinEventProcCallback ( HWINEVENTHOOK hWinEventHook, DWORD dwEvent, HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime){    /* your code here */}


There's the WM_ACTIVATE message, which is sent to the activated and deactivated windows.