System.Diagnostic.Process.Start vs System.Windows.Forms.Help

时间:2022-02-01 01:30:13

CHM文件,,Microsoft Compiled HTML Help,即“已编辑的帮助文件”,包含一系列的HTML文件,index文件和其它的导航工具,经常作为产品的帮助文件[1]。

在.Net程序中,打开这种文件最简单的方式就是调用System.Windows.Forms.Help.ShowHelp()方法。根据MSDN,重载了四种调用方式[2]。Control为父控件,string为Help文件的URL,HelpNavigator是一个枚举类型,可以采用Index或者Topic或者其它参数打开指定的界面。Object就是指定界面的一个字符串。

1 // Displays the contents of the Help file at the specified URL. 2 ShowHelp(Control, String) 3 // Displays the contents of the Help file found at the specified URL for a specific topic. 4 ShowHelp(Control, String, HelpNavigator) 5 // Displays the contents of the Help file located at the URL supplied by the user. 6 ShowHelp(Contorl, String, HelpNavigator, Object) 7 //Displays the contents of the Help file found at the specified URL for a specific keyword. 8 ShowHelp(Control, String, String)

采用这种方案打开的CHM文件与当前的应用程序处于同一个进程内,随着当前应用程序的关闭,CHM文件会一起退出。但是我们在应用的过程中发现,如果CHM文件和应用程序是通过CD光盘打开的话,CHM文件的路径会出现错误,无法打开对应的界面,显示的内容为无法找到对应的页面。

System.Diagnostic.Process.Start是用来打开一个新的进程[3]。我们可以采用这个方法来打开CHM文件。例如System.Diagnostic.Process.Start(CHMFileName),这种打开方式可以打开CHM文件的主界面。如果想要打开CHM文件的指定界面,可以利用微软提供的hh.exe程序。我们可以指定fileName为hh.exe,arguments为fileName::SpecificPage,这样就会打开指定的界面。但是这种方法打开的CHM不会随着当前的应用程序一起关闭。

[1] https://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help

[2] https://msdn.microsoft.com/en-us/library/system.windows.forms.help.showhelp(v=vs.110).aspx

[3] https://msdn.microsoft.com/en-us/library/system.diagnostics.process%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

System.Diagnostic.Process.Start vs System.Windows.Forms.Help.ShowHelp 打开CHM文件