如何只打开一个CHM文件实例? [英] How to have only one instance of the CHM file opened?

查看:45
本文介绍了如何只打开一个CHM文件实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在菜单栏中单击帮助"时,我只希望设置CHM文件的一个实例,而在再次单击时阻止它打开两次,因此,我该如何编码?

I want to set up only one instance of the CHM file when clicking on "Help" in the menubar and stopping it from opening twice when clicked again - therefore how do I code it?

我尝试将其与process.isAlive()一起使用,但是在关闭它后,我希望将计数器设置为零,该计数器仅在计数器为0时才打开另一个CHM文件.

I've tried to use it with process.isAlive(), but after I close it I want a counter set to zero, which only opens another CHM file when the counter is 0.

helpMenu.addMouseListener(new MouseAdapter() {
// do this after clicked
openCHM();
});

所以MouseEvent被触发一次.

So MouseEvent is fired once.

openCHM() {
Process p;
if(cnt == 0) {
   p = Runtime.getRuntime().exec("hh.exe Help.chm");
   cnt++;
   if(!p.isAlive()) {
      cnt = 0;
   }
}

我希望计数器为0,但是得出的结论是MouseEvent已经触发一次并且代码已经执行,因此它永远不会进入第二个if语句并将我的计数器设置为0.

I expected the counter to be 0, but then came to the conclusion that MouseEvent already fired once and the code got already executed, therefore it never goes to the second if-statement and sets my counter to 0.

编辑

如何一次打开CHM文件没有正确的答案,但是有一种变通办法,使它成为可能,我们只需要查看文件是否可重命名.

There is no correct answer how to open a CHM file once, but there is a workaround that makes it possible, we just need to look if the file is renamable or not.

protected void openCHM() {
        try {
            File file = new File("YOURNAME.chm");
            boolean renamable = file.renameTo(file); // can't rename if file is already open, returns true if renaming is possible
            if(renamable) {
                Runtime.getRuntime().exec("hh.exe YOURNAME.chm");
            } else if(!file.exists() ){
                // message: file doesn't exist (in path)
            } else {
                // file is already open
            }
        } catch () {
        }
    }

推荐答案

我不是Java程序员,但简短的故事-不可能(AFAIK).

I'm not a Java programmer but the short story - not possible (AFAIK).

您知道, hh.exe 是HTMLHelp可执行文件,并且与* .CHM文件关联.它只是一个使用HTML Help API的外壳,实际上只是托管一个浏览器窗口.

You know, hh.exe is the HTMLHelp executable and associated with *.CHM files. It's just a shell that uses the HTML Help API and is really just hosting a browser window.

HH.EXE不是单个实例,如果您使用HH.EXE三次打开CHM或另一个文件,则会出现三个帮助窗口.使用PowerShell尝试一下:

HH.EXE is not single instance, if you open a CHM or another file three times using HH.EXE, then three help windows will appear. Try it using PowerShell:

PS D:\_working> hh.exe C:\Windows\Help\htmlhelp.chm

可以使用几个客户端命令行开关来帮助属于HTML帮助可执行程序(hh.exe)的作者,因此可以在未设置HTML Help Workshop的情况下正常工作.

Several client-side command line switches are available to help authors that are part of the HTML Help executable program (hh.exe) and therefore work when HTML Help Workshop is not set up.

KeyHH.exe 年前运行着带有特殊参数.

KeyHH.exe was running years ago with special parameters.

如果直接从应用程序而不是通过诸如HH.EXE或KEYHH.EXE之类的第二个帮助程序调用HH API,则必须在关闭应用程序之前关闭所有打开的帮助窗口,否则可能会导致Windows崩溃.

If you call the HH API directly from your application, and not via a second helper program like HH.EXE or KEYHH.EXE, then you MUST close any open help windows before shutting down the application or you will probably crash Windows.

有关与该问题有关的某些信息,您可能对一次打开CHM文件.

For some information related to the problem you maybe interested in Open CHM File Once.

上面链接中的一些报价信息:

这样做时,您只是从命令行中一次又一次地调用帮助查看器,就没有使用HTML帮助API,这是打开CHM后需要访问的信息.您需要检查您的Java和Smalltalk风格是否支持对HTML Help API的调用.该API在Microsoft HTML帮助工作室的帮助文件中有详细记录,该文件是您安装的能够生成CHM的编译器软件包.

这篇关于如何只打开一个CHM文件实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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