从任务栏缩略图关闭按钮打开处理 WM_CLOSE 时未显示消息框
在 Windows 7 中尝试使用任务栏缩略图中的关闭按钮关闭窗口时(启用 aero peek 功能),尝试打开“是否要保存”对话框。
处理 WM_CLOSE 时使用 MessageBox() 不起作用。只有将鼠标光标移到缩略图之外,消息框才会显示,因此航空窥视被禁用。
许多应用程序都有这种错误行为,所以这可能是 Windows 7 中的一个设计缺陷,但对于某些程序来说它可以工作(Word、记事本、Visual Studio...),所以我想知道他们正在使用什么技巧(或者它是什么)需要以编程方式“退出”航空窥视模式)。
Windows 7 附带的小型“录音机”应用程序也有同样的问题(如果您录制了一些内容但没有保存并尝试使用缩略图关闭按钮将其关闭)...
Trying to put up a "Do you want to save"-dialog when trying to close window with close-button in taskbar thumbnail in windows 7(with aero peek active).
Using MessageBox() when processing WM_CLOSE does not work. MessageBox won't show until you move mouse cursor outside thumbnail so aero peek is disabled.
Lots of applications have this buggy behaviour so it's probably a design flaw in Windows 7, but for some programs it works (Word, Notepad, Visual Studio, ...), so I'm wondering what trick they are using(or what it takes to "exit" aero peek-mode programmatically).
The small "Sound Recorder" application that comes with Windows 7 has the same problem (if you have recorded something without saving and try to close it using thumbnail close-button)...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我编写了一个小应用程序来重现这个问题。我能够通过在调用 MessageBox 之前调用 SetForegroundWindow 成功地显示消息框。
I put together a small app to reproduce this problem. I was able to successfully get the message box to appear by calling SetForegroundWindow before calling MessageBox.
我将实现 WM_SYSCOMMAND 的处理程序并具有SC_CLOSE 行为发布一条应用程序定义的消息,该消息将显示您的 UI,并在用户想要退出时将 WM_CLOSE 发布到原始窗口。
或者,记事本似乎使用任务对话框,而不是消息框。你尝试过吗?
I would implement a handler for WM_SYSCOMMAND and have the SC_CLOSE behavior post a application-defined message, which would display your UI, and post a WM_CLOSE to the original window if the user wants to exit.
Alternatively, Notepad appears to be using a task dialog, rather than a message box. Have you tried that?