Bug ID: 910
Short desc: FOr active window changing (profile detection) consider hooking into Windows activation events?

Last changed byphil 
Reported Byphil 
Reported On2025-08-19 11:39 PM 
ProjectXMBC 
OrganizationDevelopment 
Categoryenhancement 
Priorityhigh 
Assignedphil 
Statusnew 
Target ReleaseFuture Consideration 
VersionCurrent Beta 

comment 4553 posted by phil on 2025-08-19 11:39 PM, 7 days ago

If this works, it will be better than detecting process/window changes after ALT is released AND maybe also after buttons are pressed.

Hook into Window Events

// Set up a hook to detect when foreground window actually changes
HWINEVENTHOOK hook = SetWinEventHook(
    EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND,
    NULL, ForegroundWindowProc, 0, 0,
    WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS
);

void CALLBACK ForegroundWindowProc(HWINEVENTHOOK hWinEventHook, 
    DWORD event, HWND hwnd, LONG idObject, LONG idChild, 
    DWORD dwEventThread, DWORD dwmsEventTime) {
    
    if (event == EVENT_SYSTEM_FOREGROUND && IsWindowVisible(hwnd)) {
        // This is your actual foreground window
        // Handle it here
    }
}