检测如果Windows关闭或应用程序尝试从系统菜单WM_CLOSE关闭
问题说明
我有托盘应用程序。
Onj FormCloseQuery我检查程序是否应该托盘,而不是关闭它,我把它放在托盘(CanClose:= False)
Onj FormCloseQuery I check if program should goto tray and instead of closing it I put it in tray (CanClose := False)
但是如果Windows尝试关闭我的应用程序,因为Windows关闭,我不想将我的应用程序移入托盘,但要关闭它。
But if Windows tries to close my application because of Windows shutdown I want not to move my app into tray but to close it.
Win7终止我的应用程序,但XP不会关闭,因为我的应用程序仍然在托盘中。
Win7 terminates my app, but XP doesn't close because my app remains in Tray.
如何检测Windows是否关闭 或者模式?
How can I detect if Windows is some "shutting down" mode or not?
谢谢!
正确答案
从使用 OnCloseQuery
这是错误的事件要使用。 Remy的答案解释了如何解决Windows关闭被默认的VCL结束会话消息处理阻塞。而这又是因为在 OnCloseQuery CanClose
到 False
$ c>事件。
Your problems stem from the use of OnCloseQuery
which is the wrong event to be using. Remy's answer explains how to workaround Windows shutdown being blocked by the default VCL end session message handling. And this in turn is caused by setting CanClose
to False
in the OnCloseQuery
event.
该解决方法将完成工作,但有一个更简单的方法来处理此问题。
而不是停止关闭窗体,让它继续关闭。一起删除你的 OnCloseQuery
事件。将其替换为 OnClose
事件。
That workaround will get the job done but there's a much simpler way to deal with this. Instead of stopping the form from closing, let it go ahead and close. Remove your OnCloseQuery
event altogether. Replace it with an OnClose
event.
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caNone;
Visible := False;
end;
这个相当微不足道的代码足以使您的应用程序最小化到托盘主表格关闭。
This rather trivial bit of code is enough to make your app minimize to the tray when the main form is closed.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfjgkj
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20