WIX 的 CloseApplication 功能有何作用以及应用程序如何响应此类信号
在我的 WIX 设置中,升级应用程序时,我设置了关闭可能保留需要更新的文件的应用程序的要求:
<util:CloseApplication
Id="CloseMyApp"
Target="[MyAppExe]"
CloseMessage="yes"
Description="!(loc.MyAppStillRunning)"
RebootPrompt="no"
ElevatedCloseMessage="no"
/>
另一方面,应用程序将捕获使用“用户友好的”对话框,用户可以在其中确认他或她想要关闭应用程序。
当安装程序运行 CloseApplication 时,它发现必须停止该应用程序,但它无法关闭我的应用程序。一种理论认为该对话框会阻止应用程序关闭。
所以问题是:这可能是一个问题吗?如果是这样 - 当安装程序要求应用程序关闭时,如何才能显示此确认对话框并仍然正常运行?我是否必须监听 Win32 消息(例如 WM_QUIT/WM_CLOSE),或者是否有 .NET API 可用于正确响应这些事件?
更新:根据邮件列表,CloseApplication 将向应用程序发送 WM_CLOSE。如果用户关闭应用程序与 WIX 发送的关闭消息,我仍然遇到不同行为的问题。不知道如何识别应用程序关闭的不同来源。
In the WIX setup I've got, when upgrading the application I have set a requirement to close down applications which might hold on to files which needs to be updated:
<util:CloseApplication
Id="CloseMyApp"
Target="[MyAppExe]"
CloseMessage="yes"
Description="!(loc.MyAppStillRunning)"
RebootPrompt="no"
ElevatedCloseMessage="no"
/>
The application on the other hand will capture closing down the window with a "user friendly" dialog box where the user can confirm that he or she wants to close down the application.
When the installer runs CloseApplication it finds that the application must be stopped, but it fails to close my application. One theory is that the dialog box stops the application from closing.
So the question is: Could this be a possible problem? If so - how can I have this confirmation dialog box and still behave properly when the installer asks the application to close down? Must I listen to Win32 messages (such as WM_QUIT/WM_CLOSE) or is there a .NET API which I can use to respond properly to these events?
Update: According to mailinglist, CloseApplication will send WM_CLOSE to the application. I still have the issue with having different behavior if the user closes the app vs. a close message sent by WIX. Not sure how I can identify different sources of how the application closes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的应用程序应该获得一个 WM_CLOSE,它应该作为主窗体上的“关闭”事件出现在您的 .NET 应用程序中。在处理过程中,您可以使用 Win32 API GetLastActivePopup 来检查是否有任何活动的您已打开并根据需要关闭它们的对话框。
您可以通过打开任务管理器并对应用程序执行“结束进程”来测试您的实现。这将尝试首先使用类似于 WiX 可能正在执行的方法进行温和关闭。
Your application should get a WM_CLOSE which should surface in your .NET app as a "Closing" event on your main form. In processing that, you can use the Win32 API GetLastActivePopup to check for any active dialog boxes you have open and close them as appropriate.
You can test your implementation by opening task manager and doing an "End Process" on your application. That will try to do a gentle shutdown first using a method similar to what WiX is probably doing.
当 VM_CLOSE 发送到我的 WPF 应用程序时,我听到 Jim 提到了一个 Closing 事件。在该关闭事件中,我检查 Window 类的 IsFocused 属性。当返回 false 时,我在没有任何用户确认的情况下退出应用程序。
When the VM_CLOSE gets send to my WPF application, I get as Jim mentions a Closing event. In that closing event I do a check on the IsFocused property on my Window class. When this returns false, I quit the application without any user confirmation.