• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

检测如果Windows关闭或应用程序尝试从系统菜单WM_CLOSE关闭

用户头像
it1352
帮助1

问题说明

我有托盘应用程序。

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?

谢谢!

正确答案

#1

从使用 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
系列文章
更多 icon
同类精品
更多 icon
继续加载