是否可以将代码置于关闭HTA窗口的X后面 [英] Is it possible to put code behind the X that closes a window for an HTA

查看:93
本文介绍了是否可以将代码置于关闭HTA窗口的X后面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在创建一个用作实用程序的HTA。它需要做的部分工作是将其活动输出到日志文件。如果有人要使用右上角的 X 关闭窗口,有没有办法对其进行编码,以便首先关闭日志文件?我知道您可以使用Visual Studio创建的Windows应用程序执行此操作但我不确定。



谢谢,



Rob

Hi,

I am creating an HTA to use as a utility. Part of what it needs to do is output its activity to a log file. If someone were to close the window using the X in the upper right corner, is there a way to code it so the log file is closed first? I know you can do this with Windows Apps created with Visual Studio but I'm not sure about this.

Thanks,

Rob

推荐答案

您可以通过处理事件 window.onunload 来实现。请参阅,例如: http://www.thecodingforums.com/threads/ catch-window-close-event-in-hta.931828 [ ^ ]。



-SA
You can do it by handling the event window.onunload. Please see, for example: http://www.thecodingforums.com/threads/catching-window-close-event-in-hta.931828[^].

—SA

我跑了一个测试,这应该适合我:



子窗口_onbeforeunload



MsgBox 关闭日志文件 - 清理内存



结束子



当然你会使用实际代码在应用关闭之前关闭日志文件或任何其他需要完成的任务。这只是为了演示它是如何工作的。
I ran a test and this should work for me:

Sub window_onbeforeunload

MsgBox "Close log files - Cleanup memory"

End Sub

Of course you would use code that actually closes a log file or any other tasks that need to be done before the app closes. This is merely to demonstrate how it works.


这篇关于是否可以将代码置于关闭HTA窗口的X后面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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