How to use SetWinEventHook() function to get Active Window changed message

后端 未结 1 395
失恋的感觉
失恋的感觉 2020-12-18 10:40

I have been working on a project which needs to detect current active window and get the active window title continuously. Can anyone explain me how to use SetWinEve

相关标签:
1条回答
  • 2020-12-18 11:31

    I have found the solution. EVENT_SYSTEM_FOREGROUND Event is the missing piece. The system sends this event even if the foreground window has changed to another window. We can use this event to get the current active window.

    VOID CALLBACK WinEventProcCallback ( HWINEVENTHOOK hWinEventHook, DWORD dwEvent, HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
    {
         if (dwEvent == EVENT_SYSTEM_FOREGROUND)
         {
             /* do something */
         }
    }
    
    0 讨论(0)
提交回复
热议问题