在WM_CLOSE上确认退出对话框,但不进行关机等操作. [英] Confirm quit dialog on WM_CLOSE but not for shutdown etc.

查看:144
本文介绍了在WM_CLOSE上确认退出对话框,但不进行关机等操作.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个真的退出了吗?"用户在我的应用程序上按关闭"按钮时弹出的对话框.

但是,我只希望在用户按下关闭按钮或ESC键时显示此对话框,而不是在外部源(例如Windows关闭或卸载工具)发送WM_CLOSE消息时显示此对话框. IE.它应该在关机/注销/卸载和所有其他外部情况下立即关闭.

Hi, I have a "Really quit?" dialog that pops up when the user presses the Close button on my application.

However, I _only_ want this dialog to appear when the user presses the close button or the ESC key, not when an external source (e.g. Windows Shutdown or the Uninstall tool) sends the WM_CLOSE message. I.e. it should close immediately on shutdown / logoff / when uninstalling and all other external cases.

What would be the correct way to check for this?

推荐答案

,您可以使用自定义操作 [ ^ ]仅在REMOVE处发生,它将向您的应用程序发送已注册的消息
you can spot the system wanting to shutdown with the System Shutdown messages[^]

As far as uninstall is concerned, it''s probably easiest to create a Custom Action[^] in your installer that only occurs at REMOVE which sends a registered message to your application


如果您真的想通过直接这样做WM_CLOSE的处理,然后取消关闭,请查看消息描述:
http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms632617%28v=vs.85%29.aspx [WM_CLOSE的处理.但是-请参阅我对这个问题的评论;也许您可以创建更好的应用程序设计.

—SA
If you really want to do it through direct handling of WM_CLOSE and then cancel closing, look at the message description:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632617%28v=vs.85%29.aspx[^].

As you can see, the message does not have parameters except message ID, so you don''t have any information on the cause of the message.

If you wanted to prevent closing unconditionally, you would need in WM_CLOSE message handler, you would need to return TRUE from WinProc, without calling the DefWindowProc function, but if you need to do it on the condition related to the source of the message, you don''t receive anything which gives you a clue.

You should do some work-around. Insider the application, devise a custom message like "WM_USER_CLOSING", send it inside the application process, handle it, and actually close the window or not, depending on the user''s decision. It won''t affect a handling of the message WM_CLOSE sent from external application, just as you wanted. But — please see my comment to the question; probably you can create better application design instead.

—SA


这篇关于在WM_CLOSE上确认退出对话框,但不进行关机等操作.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆