上一版的《html help 制作和使用》中没有讲到如果在visual c++ 6中使用html help,因为那时我还没把vc学好。在我用vc调用了html help之后,才发现用vc调用html help并不是一件简单的事。
在visual c++ 6中调用html help没有现成的函数,需要调用htmlhelp()这个api函数。而在调用这个函数之前,还需要在你的工程中加上htmlhelp的库和头文件:
1. 指定htmlhelp.h的路径。选择菜单“project -> settings...”,打开“project settings”对话框。选中“c/c++”选项卡,选择“category”列表框的内容为“preprocesor”,在“additional include directories”项中填入包含“htmlhelp.h”这一文件的路径。这个文件你可以在你的硬盘上找,如果你安装了“html help workshop”,那么在“html help workshop”程序目录下有个“include”目录就是。
2. 指定htmlhelp.lib的路径。按照与前面类似的方法,选择“link”选项卡,选择“category”为“input”,在“additional library path”中填入包含“htmlhelp.lib”文件的路径。同样,在“html help workshop”程序目录下的"lib"目录就是。
3. 指定lib文件。同样在“link”选项卡中,选择“category”为“general”,在“object/librarie module”中填入“htmlhelp.lib”。
4. 最后,将htmlhelp.h包含在程序中。你可以选择一个合适的位置加入“#include <htmlhelp.h>”这一句话,但我建议你将这句话加入到“stdafx.h”中。
注:以上所有内容在msdn的“including html help support files in an application”主题中均有介绍,在“搜索”选项卡中输入查找内容为“htmlhelp”即可找到该主题。
最后是大家都关心的问题,如何在程序中调用html help。
如同在visual basic 6中使用html help一样,首先需要定位帮助文件的位置。假如我们把帮助文件(.chm)放在程序路径下,那么我们该如何去获得程序路径呢?程序大本营上是使用的api函数getmodulefilename(),例如,我使用以下代码定位程序路径和取文件的完整路径文件名:
cstring apppath;
getmodulefilename(null, apppath.getbuffer(max_path), max_path);
//注:使用该api函数得到的是程序文件完整路径文件名,去掉文件名后才是路径。
apppath.releasebuffer();
int n = apppath.reversefind('\\');
cstring helpfile;
helpfile = apppath.left(n);
tchar c = helpfile.getat(n - 1);
if(c == '\\')
helpfile += "htmlhelp.chm";
else
helpfile += "\\htmlhelp.chm";
通过htmlhelp调用帮助文件(.chm)的程序代码如下:
htmlhelp(null, (lpcstr)helpfile, hh_display_topic, 0);
//直接打开帮助文件的默认主题。
或
htmlhelp(null, (lpcstr)helpfile, hh_help_context, 1);
//打开其中一个主题,实现上下文相关的帮助调用。
如此,在visual c++ 6中,你也能调用htmlhelp了。这次可是用的api函数,也就是说,略为改动你就可以用于……
上一节 回首页
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器