I am working on a Windows application. I have created a help file (.chm) using a third party tool and I call it from the Windows application. The help file is invoked successfully when I click on Help menu item or press F1 for the application.
The problem I am facing is that if I click on the menu item again or press F1 (while the application is open and I have not closed the previous help file) it opens another instance of the help file.
Let me be clear by giving an example: I want it to be just like the "Solitaire" game. No matter how many times you press F1 or the Contents menu item it shows only one help window.
我想做和“纸牌”一样的事情。我不想创建多个实例。
我希望你理解我的问题。如果我的查询有误,请告诉我。
我在下面发布了我的代码。
ProcessStartInfo info;
Process exeprocess;
以下代码位于帮助菜单项单击事件中。
private void mnuContents_Click(object sender, EventArgs e)
{
string ApplicationPath=ConfigurationSettings.AppSettings["HelpFile"].ToString();
info = new ProcessStartInfo(ApplicationPath);
//Process.Start(info);
exeprocess = Process.Start(info);
}
一种解决方案是:
让您的应用程序创建系统范围的资源(下面的示例使用 Win32 互斥体)
在生成 .chm 之前检查资源(我想您可能正在使用 ShellExec 或某些变体来生成帮助文件。
下面是示例代码(C++/Win32 代码):
http://support.microsoft.com/kb/243953 http://support.microsoft.com/kb/243953
另一种不同的方法是查看当前正在运行的进程是否与您将生成的进程相匹配。以下是此方法的示例代码:
http://www.dotnetperls.com/single-instance-windows-form http://www.dotnetperls.com/single-instance-windows-form
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)