怎樣給我的vb程序添加幫助程序?
方法一 使用F1鍵:這種方法最簡(jiǎn)單,只需如下代碼即可:Private Sub Form_Load() App.HelpFile = app.path & "\help.chm" '調(diào)用與主程序同目錄下的help.chm幫助文件,按F1鍵調(diào)用End Sub方法二 使用SendKeys方法:
Private Sub Form_Load() App.HelpFile = app.path & "\help.chm" End Sub private Sub CmdHelp_Click() SendKeys "{F1}" '發(fā)送擊鍵到活動(dòng)窗口 End Sub方法三 使用Shell函數(shù):
private Sub CmdHelp_Click()Shell "hh.exe help.chm", vbNormalFocus 'help.chm為指定的幫助文件,可包含路徑。End Sub方法四 使用HtmlHelp函數(shù):先聲明如下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指定調(diào)用者的窗口,pszFile指定要調(diào)用的文件,uCommand是發(fā)送給 HtmlHelp的命令,dwData是uCommand的參數(shù)。 然后在過(guò)程中調(diào)用:
private Sub CmdHelp_Click()dim i as stringi = app.path & "\help.chm" '用變量i記錄與主程序同目錄下的help.chm幫助文件HtmlHelpA Form1.hWnd, i, 0, 0End Sub方法五 使用ShellExecute函數(shù):先聲明如下API:Option Explicit'聲明API函數(shù)用于異步打開(kāi)一個(gè)文檔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然后在過(guò)程中調(diào)用:
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以上五種方法各有優(yōu)缺點(diǎn),從代碼的簡(jiǎn)單上講,建議使用第二種方法。從功能上講,建議使用第五種方法,因其不只用于打開(kāi)CHM幫助文件,還可用同樣的格式打開(kāi)、打印或查找一個(gè)文件或文檔(參見(jiàn)該API的說(shuō)明資料)。