CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

VB如何运行chm文件,请给为帮忙。

楼主p20001202(若日)2002-05-18 10:38:03 在 VB / 基础类 提问

运行exe可以用shell函数,但是如何通过点击一个button调用一个chm的帮助文件?是不是有什么API函数可以做到,请大家告诉我。谢谢! 问题点数:50、回复次数:10Top

1 楼roberthanker(冬天)回复于 2002-05-18 10:51:30 得分 10

Displaying   Help   by   Using   the   HtmlHelp   API  
  Because   the   current   implementation   of   the   HTML   Help   ActiveX   control   can't   be   inserted   in   a   form   and   doesn't   provide   Component   Object   Model   (COM)   interfaces,   you   must   call   its   API   directly   if   you   need   to   use   features   beyond   those   supported   by   the   methods   and   properties   available   in   VBA.   Because   Word   and   Access   don't   currently   provide   a   built-in   method   for   displaying   custom   Help   topics,   you   must   use   the   HtmlHelp   API   to   display   a   custom   Help   topic   in   those   applications.  
   
  Before   you   can   use   an   API   call   from   VBA   code,   you   must   create   a   function   declaration   in   the   Declarations   section   of   a   form,   class,   or   standard   module.   The   HtmlHelp   API   requires   a   single   function   declaration   that   looks   like   this:  
   
  Declare   Function   HtmlHelp   Lib   "HHCtrl.ocx"   Alias   "HtmlHelpA"   _  
        (ByVal   hwndCaller   As   Long,   _  
        ByVal   pszFile   As   String,   _  
        ByVal   uCommand   As   Long,   _  
        dwData   As   Any)   As   Long  
   
  This   declaration   uses   the   ANSI   version   of   the   HtmlHelp   function   exported   by   HHCtrl.ocx.   For   more   information   about   using   API   calls   from   VBA,   see   Chapter   10,   "The   Windows   API   and   Other   Dynamic-Link   Libraries."  
   
  The   arguments   of   the   HtmlHelp   function   provide   the   following   functionality.  
   
  Argument   Description    
  hwndCaller   A   handle   to   an   application   window   or   Null.   This   window   handle   may   be   used   as   a   parent,   owner,   or   message   recipient   for   HTML   Help,   depending   on   how   it   is   used.   In   VBA,   instead   of   setting   this   to   vbNullString,   set   it   to   0   (zero).    
  pszFile   File   to   display;   optionally   also   specifies   which   window   type   to   display   it   in,   delimited   with   the   right   angle   bracket   character   (filename>windowtype).   If   you   omit   the   window   type,   the   HtmlHelp   function   will   use   the   default   window   type   specified   in   the   HTML   Help   project   file.   For   uCommand   values   that   don't   require   a   source   file,   pszFile   can   be   Null,   or   0   (zero),   in   VBA.   However,   a   compiled   HTML   Help   file   is   typically   specified.      
  uCommand   The   action   to   perform;   see   the   remainder   of   this   section   for   examples   of   how   to   display   a   Help   topic   by   using   either   the   HH_HELP_CONTEXT   or   HH_DISPLAY_TOPIC   command.    
  dwData   Specifies   additional   data   depending   on   the   value   of   uCommand.   Note   that   in   this   declaration   this   argument   is   declared   As   Any,   because   this   argument   accepts   several   different   data   types.   You   must   be   careful   to   pass   the   correct   data   type   or   risk   an   invalid   page   fault   (also   known   as   general   protection   fault   [GPF]).    
   
   
  The   HtmlHelp   function   supports   a   broad   variety   of   HTML   Help   functionality   and   provides   detailed   control   unavailable   through   other   programmatic   means.   The   rest   of   this   section   describes   how   to   use   the   HtmlHelp   function   to   display   a   custom   Help   topic.   For   more   information   about   using   other   commands   with   the   uCommand   argument,   see   the   HtmlHelp   API   Reference   in   the   Help   system   for   HTML   Help   Workshop.  
   
  To   make   using   the   HtmlHelp   function   from   VBA   simpler,   in   addition   to   the   function   declaration,   you   should   also   declare   the   following   constants   to   pass   as   the   uCommand   argument:  
   
  Const   HH_DISPLAY_TOPIC   =   &H0  
  Const   HH_HELP_CONTEXT   =   &HF  
   
  The   constants   in   the   following   table   are   used   to   specify   which   uCommand   command   to   use   with   the   HtmlHelp   function   to   display   a   Help   topic.  
   
  uCommand   command   Description    
  HH_DISPLAY_TOPIC   Displays   a   Help   topic   by   passing   the   name   of   the   HTML   file   that   contains   the   topic   as   the   dwData   argument.    
  HH_HELP_CONTEXT   Displays   a   Help   topic   by   passing   the   mapped   context   ID   for   the   topic   as   the   dwData   argument.    
   
   
  The   command   you   choose   to   use   depends   on   whether   you   have   mapped   context   IDs   for   each   topic   as   described   earlier   in   this   chapter   in   "Creating   a   Help   File   to   Use   with   an   Office   Solution."   If   you   haven't   created   context   IDs,   you   must   use   the   HH_DISPLAY_TOPIC   command.   If   you   have   created   context   IDs,   you   can   use   either   command.  
   
  When   you   are   using   either   command   from   an   Office   application,   you   should   pass   0   (zero)   as   the   hwndCaller   argument   so   that   HTML   Help   will   display   the   Help   topic   in   sibling   mode.   Sibling   mode   (shown   in   Figure   13.2)   causes   HTML   Help   to   display   Help   topics   in   a   separate   top-level   overlapped   Help   window   that   is   displayed   alongside   the   calling   application.   The   user   can   freely   switch   between   the   application   and   the   Help   window.    
   
  Figure   13.2   Sibling   Mode  
   
   
   
  The   following   line   of   code   shows   how   to   display   a   Help   topic   by   using   the   HH_DISPLAY_TOPIC   command:  
   
  Call   HtmlHelp(0,   "c:\help\Sample.chm",   HH_DISPLAY_TOPIC,   By   Val   "Topic1.htm")  
   
  This   code   will   display   the   topic   authored   in   Topic1.htm,   which   is   compiled   in   the   Sample.chm   file.   Because   no   window   type   was   specified   for   the   pszFile   argument,   the   topic   will   be   displayed   by   using   the   default   window   type   specified   in   the   HTML   Help   project   file   that   was   used   when   the   Help   file   was   compiled.  
   
  The   following   line   of   code   shows   how   to   display   a   Help   topic   by   using   the   HH_HELP_CONTEXT   command:  
   
  Call   HtmlHelp(0,   "c:\help\Sample.chm>mso_small",   HH_DISPLAY_TOPIC,   By   Val   2001&)  
   
  This   code   will   display   the   topic   specified   by   the   mapped   context   ID   2001   in   the   Sample.chm   file.   The   ampersand   (&)   following   the   context   ID   is   required   to   specify   that   the   value   being   passed   to   the   HtmlHelp   function   is   a   Long   data   type.   The   topic   will   be   displayed   by   using   the   mso_small   window   type   specified   in   the   pszFile   argument.   In   order   for   this   line   of   code   to   work   correctly,   the   mso_small   window   type   must   be   specified   in   the   HTML   Help   project   file   that   was   used   when   the   Help   file   was   compiled.  
   
  览Top

2 楼jafi(胖猫先生)回复于 2002-05-18 13:32:35 得分 3

1   :   找到   c:\windows\hh.exe   这是运行   chm   的工具.    
  2   :   copy   c:\windows\hh.exe     到你程序的当前目录  
  3   :   把   chm放到   hh.exe所在的目录  
  4   :   在程序里边写      
                  shell   app.path   &   "hh.exe"   &   "   "   &   app.path   &   "help.chm"  
                  (此行请根据   shell的参数提示填写)  
   
  就   ok啦.  
   
          mrjafi@21cn.com  
  Top

3 楼jy_1201(大师,他从天空来!)回复于 2002-05-18 13:53:48 得分 8

1.声明API函数  
  Public   Declare   Function   HtmlHelp   Lib   "hhctrl.ocx"   Alias   "HtmlHelpA"   (ByVal   hwndCaller   As   Long,   ByVal   pszFile   As   String,   ByVal   uCommand   As   Long,   ByVal   dwData   As   Long)   As   Long  
  2.单击事件添加  
  Call   HtmlHelp(Me.hwnd,   App.Path   &   "*.chm(帮助文件)",   1,   0)Top

4 楼gxingmin(小高)回复于 2002-05-18 14:07:09 得分 10

''调用chm文件  
  Public   Declare   Function   htmlhelp   Lib   "hhctrl.ocx"   Alias   "HtmlHelpA"   (ByVal   hwndcaller   As   Long,   ByVal   pszfile   As   String,   ByVal   ucommand   As   Long,   ByVal   dwdata   As   Long)   As   Long  
   
  Private   Sub   MeuHelpFile_Click()  
        htmlhelp   Me.hWnd,   App.Path   &   "\帮助文件.chm",   0,   0  
  end   sub  
   
  ''调用hlp文件  
  Public   Declare   Function   WinHelp   Lib   "user32"   Alias   "WinHelpA"   (ByVal   hwnd   As   Long,   ByVal   lpHelpFile   As   String,   ByVal   wCommand   As   Long,   ByVal   dwData   As   Long)   As   Long  
  Public   Const   HELP_FINDER   =   &HB&  
  Private   Sub   Form_Load()       '主窗体载入  
        App.HelpFile   =   App.Path   &   "帮助文件.HLP"        
  end   sub  
  Private   Sub   MeuHelpFile_Click()  
        Dim   Hlp   As   Long  
        Hlp   =   WinHelp(MainForm.hwnd,   App.HelpFile,   HELP_FINDER,   CLng(0))  
  End   Sub  
  Top

5 楼softrain(曾经的月光,现在的日光)回复于 2002-05-18 14:16:46 得分 0

靠,又来晚了!Top

6 楼p20001202(若日)回复于 2002-05-19 16:37:14 得分 0

我试了一下htmlhelp这个函数似乎不行,我是希望按一个button来运行我自己编写的一个chm文件。Top

7 楼windancer(^_^)回复于 2002-05-19 16:52:17 得分 8

我有一个比较土的方法,呵呵  
  在工程->工程属性->选择帮助文件,之后就可以用f1功能键打开.chm文件,接着在button.clikc中调用api函数:keybd_event()来模拟键盘f1键,具体的api  
  调用常数可以参考"api文本浏览器"  
  Top

8 楼zhpfaff(zhp)回复于 2002-05-19 17:56:06 得分 2

用shell来打开。  
  去看看这个:  
  http://www.csdn.net/expert/topic/529/529323.xml?temp=.753338Top

9 楼starlee(StarLee)回复于 2002-05-19 21:47:56 得分 9

告诉你一个很简单的方法  
  在Form_Load()中加入一下代码:  
  App.HelpFile=App.Path+"\帮助文件名.chm"  
  在运行该帮助时,用一下代码:  
  SendKeys   "{F1}"  
  这样就行了!而且在该窗体下按下F1键也可以显示该帮助文件Top

10 楼p20001202(若日)回复于 2002-05-20 10:19:46 得分 0

谢谢各位的帮助。Top

相关问题

  • 在VB中如何运行帮助文件(*.hlp,*.chm),用Shell函数不能打开,各位大侠帮帮忙
  • 如何在VB中运行EXE文件
  • 在vb中,如何调用chm文件。
  • 如何在vb中调用chm文件
  • 请问如何在程序中运行帮助文件(*.chm or *.hlp)?
  • VB的运行库包括那几个文件?
  • VB的运行库文件有哪几个?
  • 怎么在VB里面运行现有的EXE文件
  • 关于VB运行外部EXE文件的问题。
  • VB程序运行时怎么取得自身的文件名?

关键词

  • 文件
  • 函数
  • api
  • f1
  • htmlhelp
  • chm
  • 运行
  • 调用
  • 帮助
  • topic

得分解答快速导航

  • 帖主:p20001202
  • roberthanker
  • jafi
  • jy_1201
  • gxingmin
  • windancer
  • zhpfaff
  • starlee

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo