还有,在菜单事件中mnuHelp_Click()中写什么代码,才能调用帮助文件chm???
另一个问题,我想使用另外一种方法实现,就是事件中写入模拟点击键盘F1的代码,问,怎么写?
请高手指点,重谢哦
7 个解决方案
#1
'方法一
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOW = 5
'方法二
Private Declare Function HtmlHelpA Lib "hhctrl.ocx" (ByVal hwndCaller As Long, ByVal pszFile As String, ByVal uCommand As Long, ByVal dwData As Long) As Long
Const HH_DISPLAY_TOPIC = &H0
Const HH_DISPLAY_INDEX = &H2
Const HH_HELP_CONTEXT = &HF
Const HH_DISPLAY_SEARCH = &H3
Const HH_DISPLAY_TEXT_POPUP = &HE
'接着指定CHM文件的名称和位置:
Private Sub Command1_Click()
Dim nRet As Integer
'如果这个工程没有帮助文件,显示消息给用户
'可以在“工程属性”对话框中为应用程序设置帮助文件
If Len(App.HelpFile) = 0 Then
MsgBox "无法显示帮助目录,该工程没有相关联的帮助。", vbInformation, Me.Caption
Else
On Error Resume Next
SendKeys "{F1}"
If Err Then
MsgBox Err.Description
End If
End If
End Sub
Private Sub Command2_Click()
HtmlHelpA Form1.hWnd, App.Path & "\help.CHM", 0, 0
End Sub
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOW = 5
'方法二
Private Declare Function HtmlHelpA Lib "hhctrl.ocx" (ByVal hwndCaller As Long, ByVal pszFile As String, ByVal uCommand As Long, ByVal dwData As Long) As Long
Const HH_DISPLAY_TOPIC = &H0
Const HH_DISPLAY_INDEX = &H2
Const HH_HELP_CONTEXT = &HF
Const HH_DISPLAY_SEARCH = &H3
Const HH_DISPLAY_TEXT_POPUP = &HE
'接着指定CHM文件的名称和位置:
Private Sub Command1_Click()
Dim nRet As Integer
'如果这个工程没有帮助文件,显示消息给用户
'可以在“工程属性”对话框中为应用程序设置帮助文件
If Len(App.HelpFile) = 0 Then
MsgBox "无法显示帮助目录,该工程没有相关联的帮助。", vbInformation, Me.Caption
Else
On Error Resume Next
SendKeys "{F1}"
If Err Then
MsgBox Err.Description
End If
End If
End Sub
Private Sub Command2_Click()
HtmlHelpA Form1.hWnd, App.Path & "\help.CHM", 0, 0
End Sub
#2
调用写:
SendKeys "{F1}"
模块中写:
Dim strFile As String
strFile = App.Path & "\" & "help.chm"
App.HelpFile = strFile
SendKeys "{F1}"
模块中写:
Dim strFile As String
strFile = App.Path & "\" & "help.chm"
App.HelpFile = strFile
#3
Shell "hh " & "f:\HelpApp.chm", vbNormalFocus
#4
直接Shell调用
#5
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Command1_Click()
ShellExecute me.hWnd, "open", App.Path & "\help.CHM", "", "",1
End Sub
Private Sub Command1_Click()
ShellExecute me.hWnd, "open", App.Path & "\help.CHM", "", "",1
End Sub
#6
在工程属性里选择帮助文件
在菜单里写:
SendKeys "{F1}"
在菜单里写:
SendKeys "{F1}"
#7
在VB中调用CHM 帮助的几种方法
一个应用程序不论编制得如何完美,在很多情况下用户还是会对如何使用它提出问题。 visual basic 提供了对两种不同帮助系统的支持:传统的 windows 帮助系统 (winhelp)和新的 html 帮助(chm帮助)。当我们制作好帮助文件后,就需要在程序的适当位置编写代码进行调用,本文将讨论几种在程序中调用chm帮助文件的方法。
方法一 使用f1键:
这种方法最简单,只需如下代码即可:
private sub form_load()
app.helpfile = app.path & "\help.chm" '调用与主程序同目录下的help.chm帮助文件,按f1键调用
end sub
方法二 使用sendkeys方法:
private sub form_load()
app.helpfile = app.path & "\help.chm"
end sub
private sub cmdhelp_click()
sendkeys "{f1}" '发送击键到活动窗口
end sub
方法三 使用htmlhelp函数:
先声明如下api:
option explicit
private declare function htmlhelpa lib "hhctrl.ocx" (byval hwndcaller as long, byval pszfile as string, byval ucommand as long, byval dwdata as long) as long
'hwndcaller指定调用者的窗口,pszfile指定要调用的文件,ucommand是发送给 htmlhelp的命令,dwdata是ucommand的参数。
然后在过程中调用:
private sub cmdhelp_click()
dim i as string
i = app.path & "\help.chm" '用变量i记录与主程序同目录下的help.chm帮助文件
htmlhelpa form1.hwnd, i, 0, 0
end sub
方法四 使用shellexecute函数:
先声明如下api:
option explicit
'声明api函数用于异步打开一个文档
private declare function shellexecute lib "shell32.dll" alias "shellexecutea" (byval hwnd as long, byval lpoperation as string, byval lpfile as string, byval lpparameters as string, byval lpdirectory as string, byval nshowcmd as long) as long
private const sw_shownormal = 1
然后在过程中调用:
private sub cmdhelp_click()
dim a as long
dim b as string
b = app.path & "\help.chm" '用变量b记录与主程序同目录下的help.chm帮助文件
a = shellexecute (0, "open", b, "", "", sw_shownormal)
end sub
建议使用第二种方法。
一个应用程序不论编制得如何完美,在很多情况下用户还是会对如何使用它提出问题。 visual basic 提供了对两种不同帮助系统的支持:传统的 windows 帮助系统 (winhelp)和新的 html 帮助(chm帮助)。当我们制作好帮助文件后,就需要在程序的适当位置编写代码进行调用,本文将讨论几种在程序中调用chm帮助文件的方法。
方法一 使用f1键:
这种方法最简单,只需如下代码即可:
private sub form_load()
app.helpfile = app.path & "\help.chm" '调用与主程序同目录下的help.chm帮助文件,按f1键调用
end sub
方法二 使用sendkeys方法:
private sub form_load()
app.helpfile = app.path & "\help.chm"
end sub
private sub cmdhelp_click()
sendkeys "{f1}" '发送击键到活动窗口
end sub
方法三 使用htmlhelp函数:
先声明如下api:
option explicit
private declare function htmlhelpa lib "hhctrl.ocx" (byval hwndcaller as long, byval pszfile as string, byval ucommand as long, byval dwdata as long) as long
'hwndcaller指定调用者的窗口,pszfile指定要调用的文件,ucommand是发送给 htmlhelp的命令,dwdata是ucommand的参数。
然后在过程中调用:
private sub cmdhelp_click()
dim i as string
i = app.path & "\help.chm" '用变量i记录与主程序同目录下的help.chm帮助文件
htmlhelpa form1.hwnd, i, 0, 0
end sub
方法四 使用shellexecute函数:
先声明如下api:
option explicit
'声明api函数用于异步打开一个文档
private declare function shellexecute lib "shell32.dll" alias "shellexecutea" (byval hwnd as long, byval lpoperation as string, byval lpfile as string, byval lpparameters as string, byval lpdirectory as string, byval nshowcmd as long) as long
private const sw_shownormal = 1
然后在过程中调用:
private sub cmdhelp_click()
dim a as long
dim b as string
b = app.path & "\help.chm" '用变量b记录与主程序同目录下的help.chm帮助文件
a = shellexecute (0, "open", b, "", "", sw_shownormal)
end sub
建议使用第二种方法。
#1
'方法一
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOW = 5
'方法二
Private Declare Function HtmlHelpA Lib "hhctrl.ocx" (ByVal hwndCaller As Long, ByVal pszFile As String, ByVal uCommand As Long, ByVal dwData As Long) As Long
Const HH_DISPLAY_TOPIC = &H0
Const HH_DISPLAY_INDEX = &H2
Const HH_HELP_CONTEXT = &HF
Const HH_DISPLAY_SEARCH = &H3
Const HH_DISPLAY_TEXT_POPUP = &HE
'接着指定CHM文件的名称和位置:
Private Sub Command1_Click()
Dim nRet As Integer
'如果这个工程没有帮助文件,显示消息给用户
'可以在“工程属性”对话框中为应用程序设置帮助文件
If Len(App.HelpFile) = 0 Then
MsgBox "无法显示帮助目录,该工程没有相关联的帮助。", vbInformation, Me.Caption
Else
On Error Resume Next
SendKeys "{F1}"
If Err Then
MsgBox Err.Description
End If
End If
End Sub
Private Sub Command2_Click()
HtmlHelpA Form1.hWnd, App.Path & "\help.CHM", 0, 0
End Sub
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOW = 5
'方法二
Private Declare Function HtmlHelpA Lib "hhctrl.ocx" (ByVal hwndCaller As Long, ByVal pszFile As String, ByVal uCommand As Long, ByVal dwData As Long) As Long
Const HH_DISPLAY_TOPIC = &H0
Const HH_DISPLAY_INDEX = &H2
Const HH_HELP_CONTEXT = &HF
Const HH_DISPLAY_SEARCH = &H3
Const HH_DISPLAY_TEXT_POPUP = &HE
'接着指定CHM文件的名称和位置:
Private Sub Command1_Click()
Dim nRet As Integer
'如果这个工程没有帮助文件,显示消息给用户
'可以在“工程属性”对话框中为应用程序设置帮助文件
If Len(App.HelpFile) = 0 Then
MsgBox "无法显示帮助目录,该工程没有相关联的帮助。", vbInformation, Me.Caption
Else
On Error Resume Next
SendKeys "{F1}"
If Err Then
MsgBox Err.Description
End If
End If
End Sub
Private Sub Command2_Click()
HtmlHelpA Form1.hWnd, App.Path & "\help.CHM", 0, 0
End Sub
#2
调用写:
SendKeys "{F1}"
模块中写:
Dim strFile As String
strFile = App.Path & "\" & "help.chm"
App.HelpFile = strFile
SendKeys "{F1}"
模块中写:
Dim strFile As String
strFile = App.Path & "\" & "help.chm"
App.HelpFile = strFile
#3
Shell "hh " & "f:\HelpApp.chm", vbNormalFocus
#4
直接Shell调用
#5
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Command1_Click()
ShellExecute me.hWnd, "open", App.Path & "\help.CHM", "", "",1
End Sub
Private Sub Command1_Click()
ShellExecute me.hWnd, "open", App.Path & "\help.CHM", "", "",1
End Sub
#6
在工程属性里选择帮助文件
在菜单里写:
SendKeys "{F1}"
在菜单里写:
SendKeys "{F1}"
#7
在VB中调用CHM 帮助的几种方法
一个应用程序不论编制得如何完美,在很多情况下用户还是会对如何使用它提出问题。 visual basic 提供了对两种不同帮助系统的支持:传统的 windows 帮助系统 (winhelp)和新的 html 帮助(chm帮助)。当我们制作好帮助文件后,就需要在程序的适当位置编写代码进行调用,本文将讨论几种在程序中调用chm帮助文件的方法。
方法一 使用f1键:
这种方法最简单,只需如下代码即可:
private sub form_load()
app.helpfile = app.path & "\help.chm" '调用与主程序同目录下的help.chm帮助文件,按f1键调用
end sub
方法二 使用sendkeys方法:
private sub form_load()
app.helpfile = app.path & "\help.chm"
end sub
private sub cmdhelp_click()
sendkeys "{f1}" '发送击键到活动窗口
end sub
方法三 使用htmlhelp函数:
先声明如下api:
option explicit
private declare function htmlhelpa lib "hhctrl.ocx" (byval hwndcaller as long, byval pszfile as string, byval ucommand as long, byval dwdata as long) as long
'hwndcaller指定调用者的窗口,pszfile指定要调用的文件,ucommand是发送给 htmlhelp的命令,dwdata是ucommand的参数。
然后在过程中调用:
private sub cmdhelp_click()
dim i as string
i = app.path & "\help.chm" '用变量i记录与主程序同目录下的help.chm帮助文件
htmlhelpa form1.hwnd, i, 0, 0
end sub
方法四 使用shellexecute函数:
先声明如下api:
option explicit
'声明api函数用于异步打开一个文档
private declare function shellexecute lib "shell32.dll" alias "shellexecutea" (byval hwnd as long, byval lpoperation as string, byval lpfile as string, byval lpparameters as string, byval lpdirectory as string, byval nshowcmd as long) as long
private const sw_shownormal = 1
然后在过程中调用:
private sub cmdhelp_click()
dim a as long
dim b as string
b = app.path & "\help.chm" '用变量b记录与主程序同目录下的help.chm帮助文件
a = shellexecute (0, "open", b, "", "", sw_shownormal)
end sub
建议使用第二种方法。
一个应用程序不论编制得如何完美,在很多情况下用户还是会对如何使用它提出问题。 visual basic 提供了对两种不同帮助系统的支持:传统的 windows 帮助系统 (winhelp)和新的 html 帮助(chm帮助)。当我们制作好帮助文件后,就需要在程序的适当位置编写代码进行调用,本文将讨论几种在程序中调用chm帮助文件的方法。
方法一 使用f1键:
这种方法最简单,只需如下代码即可:
private sub form_load()
app.helpfile = app.path & "\help.chm" '调用与主程序同目录下的help.chm帮助文件,按f1键调用
end sub
方法二 使用sendkeys方法:
private sub form_load()
app.helpfile = app.path & "\help.chm"
end sub
private sub cmdhelp_click()
sendkeys "{f1}" '发送击键到活动窗口
end sub
方法三 使用htmlhelp函数:
先声明如下api:
option explicit
private declare function htmlhelpa lib "hhctrl.ocx" (byval hwndcaller as long, byval pszfile as string, byval ucommand as long, byval dwdata as long) as long
'hwndcaller指定调用者的窗口,pszfile指定要调用的文件,ucommand是发送给 htmlhelp的命令,dwdata是ucommand的参数。
然后在过程中调用:
private sub cmdhelp_click()
dim i as string
i = app.path & "\help.chm" '用变量i记录与主程序同目录下的help.chm帮助文件
htmlhelpa form1.hwnd, i, 0, 0
end sub
方法四 使用shellexecute函数:
先声明如下api:
option explicit
'声明api函数用于异步打开一个文档
private declare function shellexecute lib "shell32.dll" alias "shellexecutea" (byval hwnd as long, byval lpoperation as string, byval lpfile as string, byval lpparameters as string, byval lpdirectory as string, byval nshowcmd as long) as long
private const sw_shownormal = 1
然后在过程中调用:
private sub cmdhelp_click()
dim a as long
dim b as string
b = app.path & "\help.chm" '用变量b记录与主程序同目录下的help.chm帮助文件
a = shellexecute (0, "open", b, "", "", sw_shownormal)
end sub
建议使用第二种方法。