How to track Application closed event in c++ winapp?

223 views Asked by At

I wanted to know if any application in the foreground(except this application) is closed by clicking the cross button on the top-right or any other way like Ctrl + f4. Here is what I have created so far:

  1. create window event
void CALLBACK WinEventProc( 
    HWINEVENTHOOK hWinEventHook,
    DWORD         event,
    HWND          hwnd,
    LONG          idObject,
    LONG          idChild,
    DWORD         dwEventThread,
    DWORD         dwmsEventTime 
) {
    handleProcess(hwnd);
    // handleProcess does other operations
}
  1. Call the window event in wWinMain()
...
winDestructionHook = SetWinEventHook(EVENT_OBJECT_DESTROY, EVENT_OBJECT_DESTROY,
                     NULL, WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
...

The problem here is the window event is triggered without any window-closed action, but I wanted to activate it only on application closed.

0

There are 0 answers