拦截WM_CLOSE以进行清除操作

问题描述:

我有一个外部应用程序调用我的应用程序,应该在作业完成时结束。来自此外部应用程序的日志声称它在我的应用程序中使用 WM_CLOSE

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 on my app.

如何截取 WM_CLOSE 消息在我的应用程序中做一些清理操作?我尝试了 at_exit()并将它包装在类中,但我认为我有错误的方法。

How can I intercept the WM_CLOSE message in my application to do some cleanup operations? I tried at_exit() and wrapping it in a class, but I think I have the wrong approach.

您可以在消息循环中处理WM_CLOSE以执行任何必要的清理,甚至中止关闭(通过返回1而不是0)。参见例如这是: http://cboard.cprogramming.com/windows -programming / 141438-handling-wm_close-wm_destroy.html#post1056273

You could just handle WM_CLOSE in your message loop to do whatever cleanup is necessary, or even abort the close (by returning 1 instead of 0). See e.g. this: http://cboard.cprogramming.com/windows-programming/141438-handling-wm_close-wm_destroy.html#post1056273

编辑:对于控制台应用程序,可能会感兴趣: http://support.microsoft.com/kb/178893

for console applications, this may be of interest: http://support.microsoft.com/kb/178893