Several methods of calling CHM Help in VB

Source: Internet
Author: User
Several methods of calling CHM Help in VB

No matter how perfect an application is, in many cases the user will still ask questions about how to use it. Visual Basic provides support for two different help systems: the traditional Windows Help system (WINHELP) and the new HTML Help (CHM help). When we make a good help file, we need to write code in the appropriate place in the program to invoke it, and this article discusses several ways to call CHM Help files in your program.
Method one uses the F1 key:
This is the easiest way to do this, with just the following code:
Private Sub Form_Load ()
App.helpfile = App.Path & "\help.chm" calls the Help.chm Help file in the same directory as the main program, which is called by the F1 key
End Sub

Method two uses SendKeys method:
Private Sub Form_Load ()
App.helpfile = App.Path & "\help.chm"
End Sub
Private Sub Cmdhelp_click ()
SendKeys ' {F1} ' sends keystrokes to the active window
End Sub

Method three uses the Shell function:
Private Sub Cmdhelp_click ()
The Shell "hh.exe Help.chm", Vbnormalfocus ' Help.chm for the specified help file, can contain a path.
End Sub

Method four uses the HTMLHELP function:
Declare the following API first:
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 specifies the caller's window, pszfile specifies the file to invoke, Ucommand is the command sent to HTMLHelp, Dwdata is the Ucommand parameter.
Then call in the procedure:
Private Sub Cmdhelp_click ()
Dim i As String
i = App.Path & "\help.chm" with variable i records help.chm Help files in the same directory as the main program
Htmlhelpa Form1.hwnd, I, 0, 0
End Sub

Method Five uses the ShellExecute function:
Declare the following API first:
Option Explicit
' Declare API function to open a document asynchronously
Private Declare Function shellexecute Lib "Shell32.dll" Alias "Shellexecutea" (ByVal hwnd as Long, ByVal lpoperation as St Ring, ByVal lpfile As String, ByVal lpparameters as String, ByVal lpdirectory as String, ByVal nShowCmd as long) as long
Private Const sw_shownormal = 1
Then call in the procedure:
Private Sub Cmdhelp_click ()
Dim A As Long
Dim B as String
b = App.Path & "\help.chm" using variable B to record Help.chm help files in the same directory as the main program
A = ShellExecute (0, "open", B, "", "", SW_SHOWNORMAL)
End Sub
Each of the five methods has advantages and disadvantages, and the second method is recommended for simple code. Functionally, the fifth method is recommended, because it is not only used to open the CHM help file, but it can also open, print, or locate a file or document in the same format (see the API's descriptive information).





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.