Bug ID:  910  FOr active window changing (profile detection) consider hooking into Windows activation events?    
 
Created by phil on 2025-08-19 11:39 PM, 7 days ago
Project:  XMBC
Organization:  Development
Category:  enhancement
Priority:  high
Assigned to:  phil  
Status:  new
Target Release:Future Consideration
Version:Current Beta
 
 

show inline images      show change history

 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
    }
}