Intercept WM_CLOSE for cleanup operations

前端 未结 4 862
悲哀的现实
悲哀的现实 2021-01-22 06:58

I have an external application that calls my application and is supposed to end it when the job is done. The log from this external application claims it uses WM_CLOSE

4条回答
  •  抹茶落季
    2021-01-22 07:38

    The easiest way I think is to call PeekMessage from time to time.

    BOOL IsCloseEventReceived()
    {
        MSG msg;
        return PeekMessage(&msg, NULL, WM_CLOSE, WM_CLOSE, PM_NOREMOVE);
    }
    

    This function should work to check if a WM_CLOSE message has been posted. It's not blocking, and you'll need to call it on a regular basis.

    I might be wrong, but I think you don't need a hidden window to handle messages, a message queue is attached to your process the first time you call a messages-related function, like PeekMessage. However if you receive a WM_CLOSE message prior to your first call of this function it might be lost.

提交回复
热议问题