方法一 使用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方法三 使用Shell函式:private Sub CmdHelp_Click()Shell "hh.exe help.chm", vbNormalFocus "help.chm為指定的幫助檔案,可包含路徑。End Sub方法四 使用HtmlHelp函式:先宣告如下API:Option ExplicitPrivate 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 stringi = app.path & "\help.chm" "用變數i記錄與主程式同目錄下的help.chm幫助檔案HtmlHelpA Form1.hWnd, i, 0, 0End 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 LongPrivate Const SW_SHOWNORMAL = 1然後在過程中呼叫:private Sub CmdHelp_Click()dim a as longDim b As Stringb = App.Path & "\help.chm" "用變數b記錄與主程式同目錄下的help.chm幫助檔案a = ShellExecute (0, "open", b, "", "", SW_SHOWNORMAL)End Sub以上五種方法各有優缺點,從程式碼的簡單上講,建議使用第二種方法。從功能上講,建議使用第五種方法,因其不只用於開啟CHM幫助檔案,還可用同樣的格式開啟、列印或查詢一個檔案或文件(參見該API的說明資料)。
方法一 使用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方法三 使用Shell函式:private Sub CmdHelp_Click()Shell "hh.exe help.chm", vbNormalFocus "help.chm為指定的幫助檔案,可包含路徑。End Sub方法四 使用HtmlHelp函式:先宣告如下API:Option ExplicitPrivate 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 stringi = app.path & "\help.chm" "用變數i記錄與主程式同目錄下的help.chm幫助檔案HtmlHelpA Form1.hWnd, i, 0, 0End 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 LongPrivate Const SW_SHOWNORMAL = 1然後在過程中呼叫:private Sub CmdHelp_Click()dim a as longDim b As Stringb = App.Path & "\help.chm" "用變數b記錄與主程式同目錄下的help.chm幫助檔案a = ShellExecute (0, "open", b, "", "", SW_SHOWNORMAL)End Sub以上五種方法各有優缺點,從程式碼的簡單上講,建議使用第二種方法。從功能上講,建議使用第五種方法,因其不只用於開啟CHM幫助檔案,還可用同樣的格式開啟、列印或查詢一個檔案或文件(參見該API的說明資料)。