How to Load the Windows Help File Using WordBasic

ID: Q126087


The information in this article applies to:
  • Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, version 7.0
  • Microsoft Word for Windows NT, version 6.0


SUMMARY

This article describes how to use WordBasic to load your own Windows Help file.

Below is a sample WordBasic macro that calls the WinHelp() Windows API function.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Word Version 6.0 for Windows


REM The declaration for WinHelp is as follows:
Declare Sub WinHelp Lib "User" (hWnd As Integer, lpHelpFile$ As String,
wCommand As Integer, dwData As Long)

REM The GetFocus SDK function to obtain the handle of Word which is the
REM hWnd parameter to WinHelp
Declare Function GetFocus Lib "User"() As Integer

Sub Main
 hWnd = GetFocus
 WinHelp (hWnd, "c:\winword\winword.hlp", 3, 0)
End Sub 

Word Version 6.0 for Windows NT, Word 7.0 for Windows 95


REM The declaration for WinHelp32 is as follows:
Declare Function WinHelp Lib "user32" Alias "WinHelpA"(hwnd As Long,
lpHelpFile$ As String,
wCommand As Long, dwData As String) As Long

REM The GetFocus SDK function to obtain the handle of Word which is the
REM hWnd parameter to WinHelp
Declare Function GetFocus Lib "user32" Alias "GetFocus"() As Long

Sub Main
hWnd = GetFocus
WinHelp(hWnd, "c:\msoffice\winword\wrdbasic.hlp", 261, "")
End Sub 


MORE INFORMATION

The hWnd parameter is the window handle to Word, the active application.

The lpHelpFile$ parameter is the path and name of the Help file.

The wCommand parameter to the WinHelp function is set to the number 3 so that Help will display the contents or first page of the Help file.

See below for an explanation of the dwData parameter.

You can also go to a particular section of a Help file depending upon a keyword by doing the following:

  1. In your Help file, create a footnote that contains a keyword.


  2. From the Insert menu, choose Footnote.


  3. Select Custom Mark and type the letter K.


  4. Use this text as the text$ field for the Help call.


For example, if you define a Keyword called "normal view" in your Help file, call it this way:

Word Version 6.0 for Windows


Declare Sub WinHelp Lib "User" (hWnd As Integer, helpfilename$ As String,
wCommand As Integer, dwData As String)
Declare Function GetFocus Lib "User"() As Integer

Sub Main
 helpfilename$ = "c:\winword\winword.hlp"
 hwnd = GetFocus
 text$ = "normal view"
 WinHelp(hwnd, helpfilename$, 257, text$)
End Sub 

Word 6.0 for Windows NT, Word 7.0 for Windows 95


Declare Function WinHelp Lib "user32" Alias "WinHelpA"(hwnd As Long,
helpfilename$ As String,
wCommand As Long, dwData As String) As Long
Declare Function GetFocus Lib "user32" Alias "GetFocus"() As Long

Sub Main
 helpfilename$ ="c:\msoffice\winword\wrdbasic.hlp"
 hWnd = GetFocus
 text$ = "msgbox$"
 WinHelp(hWnd, helpfilename$, 257, text$)
End Sub 
Notice that the dwData parameter can be either Long or a String depending on how you are calling the WinHelp function.

NOTE: Always call dwData as String from 32 bit versions of Word.

wCommand parameter     Defined in Windows.H     Decimal Equivalent
==================     ====================     ==================
HELP_CONTEXT           0x0001                   1
HELP_QUIT              0x0002                   2
HELP_INDEX             0x0003                   3
HELP_CONTENTS          0x0003                   3
HELP_HELPONHELP        0x0004                   4
HELP_SETINDEX          0x0005                   5
HELP_SETCONTENTS       0x0005                   5
HELP_CONTEXTPOPUP      0x0008                   8
HELP_FORCEFILE         0x0009                   9
HELP_KEY               0x0101                   257
HELP_COMMAND           0x0102                   258
HELP_PARTIALKEY        0x0105                   261 


REFERENCES

Microsoft Word for Windows 6.0 On-Line Help, WordBasic, Declare Example

Microsoft Windows SDK "Programming Tools," Chapter 3, "Creating Help Files"

Microsoft Windows SDK "Programmer's Reference, Volume 2: Functions," pages 985-988

Additional query words: 2.0 6.0 winword 7.0 word95 word7 word6 winword winword2 winapi

Keywords : kbinterop
Version : 2.x 6.0 6.0a 6.0c 7.0
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: September 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.