Is there Windows system event on active window changed?

后端 未结 2 1712
一生所求
一生所求 2020-11-27 05:15

The desktop application I\'m developing need to know what windows were active while the application was run. Currently it performs GetForegroundWindow() call (o

相关标签:
2条回答
  • 2020-11-27 05:39

    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 */
    }
    
    0 讨论(0)
  • 2020-11-27 05:45

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

    0 讨论(0)
提交回复
热议问题