
WinHelp 16 Bit API Routines
Disclaimer: HTML has limited formatting capabilities. For that reason, routines on this page do not conform to normally accepted indention protocols. Elsewise, these routines work; I make no claim they are "good form."
'Declare these functions and consts in the form's declarations section, or in a separate module file (*.bas). The declaration should be one unbroken line or insert line breaks as supported by your version of Visual basic.
Declare Function WinHelp Lib
"User" (ByVal hWnd As Integer,
ByVal lpHelpFile As String, ByVal wCommand As Integer, ByVal dwData As Any) As Integer
Global Const HELP_CONTENTS =
&H3
Global Const HELP_CONTEXT =
&H1
Global Const HELP_FORCEFILE =
&H9
Global Const HELP_HELPONHELP =
&H4
Global Const HELP_KEY =
&H101
Global Const HELP_PARTIALKEY =
&H105
Global Const HELP_QUIT = &H2
'Note: Many an experienced programmer will tell you declaring an API
or variable "As Any" is asking for trouble. If only one function is needed, call
the dwData variable as a Integer (%) or String ($) as required. If both functions are
needed, you may want to declare the API twice, once as a "Integer" (%) and once
as a "String" ($). The second declaration might look like this (note the added
"dw"):
The declaration should be one unbroken line
or insert line breaks as supported by your version of Visual basic.
Declare Function dwWinHelp Lib "User"
(ByVal hWnd As Integer, ByVal lpHelpFile As String, ByVal wCommand As Integer, ByVal dwData As String) As Integer
'To open the help file from the
application.
Sub mnuHelpOpen()
Dim Path$, Drive$, helpfile$, x%
'direct path to application directory / folder
Path$ = App.Path
Drive$ = Left$(Path$, 2)
ChDrive Drive$
ChDir Path$
helpfile$ = "xxxxx.hlp"
'To open a help file to the first topic (usually the
contents topic) use the following routine:
x% = WinHelp(x%, helpfile$,
HELP_FORCEFILE, "")
'To open a help file to the designated contents topic
([OPTIONS] section of the project file) use the following routine:
x% = WinHelp(x%, helpfile$,
HELP_CONTENTS, "")
'To open a help file to a designated topic ([MAP]
section of the project file) use the following routine:
Dim numContextId%
numContextId% = (context id)
x% = WinHelp(x%, helpfile$,
HELP_CONTEXT, numContextId%)
End
End Sub
'WinHelp API call to Windows help file (Help On Help).
Sub mnuSearch()
Dim Path$, Drive$, helpfile$, x%
'direct path to application directory / folder
Path$ = App.Path
Drive$ = Left$(Path$, 2)
ChDrive Drive$
ChDir Path$
helpfile$ = "xxxxx.hlp"
x% = WinHelp(x%, helpfile$,
HELP_HELPONHEL , "")
End
End Sub
'WinHelp API call to help file Index (search engine).
Sub mnuSearch()
Dim Path$, Drive$, helpfile$, x%
'direct path to application directory / folder
Path$ = App.Path
Drive$ = Left$(Path$, 2)
ChDrive Drive$
ChDir Path$
helpfile$ = "xxxxx.hlp"
x% = WinHelp(x%, helpfile$,
HELP_PARTIALKEY , "")
End
End Sub
'WinHelp API call to close the associated help file when the end user exits the application.
Sub Form_Unload(Cancel As Integer)
Dim Path$, Drive$, helpfile$, x%
'direct path to application directory / folder
Path$ = App.Path
Drive$ = Left$(Path$, 2)
ChDrive Drive$
ChDir Path$
helpfile$ = "xxxxx.hlp"
x% = WinHelp(x%, helpfile$,
HELP_QUIT, "")
End
End Sub
Note: If you are invoking the WinHelp API in several routines, you
may want to make a separate application path routine.
'Visual Basic 4.0 has "What's This" help capability, but you must give up a number of options to use it - and earlier version do not have any capability. In lieu of using the core language function, these routines use the WinHelp API and the HELP_KEY const to simulate the "What's This" by use of the right mouse button.
Sub buttonHelp_MouseUp(Button As Integer, Shift As Integer, X As Single, Y
As Single)
If Button = RIGHT_BUTTON Then
PopupMenu mnuWhatHelp
End If
End Sub
Create a secondary window(s) in the help project file using RGB (255, 255, 226) as
the background color. Add a unique word or phrase with the "K" footnote in the
*.rtf file topic, then use that same word or phrase in the following routine.
Sub mnuWhatHelpPU_Click()
Dim x%, keyWord$, helpfile$, Drive$, Path$
''direct path to application directory / folder
Path$ = App.Path
Drive$ = Left$(Path$, 2)
ChDrive Drive$
ChDir Path$
helpfile$ = "xxxxx.hlp"
keyWord$ = "What Is The Help Button"
x% = WinHelp(x%, helpfile, HELP_KEY, keyWord$)
End Sub
Note: All "K" footnotes are displayed
in the help file index, so the word or phrase selected should be intelligible. Also,
whereas calls from the VB will direct topics into a secondary window, calls from the
WinHelp 3.1 Index will not. To ensure "What's This" topics will be displayed in
the secondary window - add this footnote to the *.rtf topic.
!IfThenElse(Not(IsMark(`StopRecurse')),`SaveMark(`StopRecurse');
JI(`xxxx.hlp>secondary window name',`topic context string')',
`DeleteMark(`StopRecurse');CloseWindow(`main')')
In lieu of matching context -ids with
context strings in the [MAP] section of the project
file, you can use the HELP_KEY const to create context sensitive help (F1). Add a
unique word or phrase with the "K" footnote in the *.rtf file topic, then use
that same work or phrase in the following routine.
Note: All "K" footnotes are displayed in the help file
index, so the word or phrase selected should be intelligible. Normally there is no reason
to use this method in lieu of context-ids; however if you are using HELP_KEY to simulate
"What's This" type help, then this routine is useful.
Sub buttonHelp_KeyDown(KeyCode As Integer, Shift As Integer)
Dim x%, keyWord$, helpfile$
If KeyCode = Key_F1 Then
'required when running 16 bit code under Windows95 -
else the F1 call does not work
KeyCode = 0
'direct path to application
directory / folder
Path$ = App.Path
Drive$ = Left$(Path$, 2)
ChDrive Drive$
ChDir Path$
helpfile$ = "xxxxx.hlp"
keyWord$ = "What Is The Help Button"
x% = WinHelp(x%,
"helpfile", HELP_KEY, keyWord$)
End If
End Sub
| The Freelance Story Teller |
| Voice: 405 720 7995 |
| Fax: 405 720 7995 |
| 11808 Silvermoon Drive, Oklahoma City, OK 73162 |