Opening a CHM file

G

Gman

Code I use.... but not written by me:

Option Explicit
Option Private Module

Const HH_DISPLAY_TOPIC = &H0
Const HH_SET_WIN_TYPE = &H4
Const HH_GET_WIN_TYPE = &H5
Const HH_GET_WIN_HANDLE = &H6
Const HH_DISPLAY_TEXT_POPUP = &HE ' Display string resource ID or
' text in a pop-up window.
Const HH_HELP_CONTEXT = &HF ' Display mapped numeric value in
' dwData.
Const HH_TP_HELP_CONTEXTMENU = &H10 ' Text pop-up help, similar to
' WinHelp's HELP_CONTEXTMENU.
Const HH_TP_HELP_WM_HELP = &H11 ' text pop-up help, similar to
' WinHelp's HELP_WM_HELP.

Declare Function HtmlHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" _
(ByVal hwndCaller As Long, ByVal pszFile As String, _
ByVal uCommand As Long, ByVal dwData As Long) As Long


' HTML Help file launched in response to a button click:
Private Sub ViewHelpFile()

' hWnd is a Long defined elsewhere to be the window handle
' that will be the parent to the help window.

Dim hwndHelp As Long
Dim hWnd As Long

' The return value is the window handle of the created help window.
hwndHelp = HtmlHelp(hWnd, "myfile.chm", HH_DISPLAY_TOPIC, 0)

End Sub


' ' A specific topic identified by the variable ContextID is launched
' ' in response to this button click:
Private Sub HH_HELP_Click()
Dim hwndHelp As Long
'The return value is the window handle of the created help window.
hwndHelp = HtmlHelp(hWnd, "myfile.chm", HH_HELP_CONTEXT, ContextID)
End Sub
 
A

Avi Benita

Thanks for the prompt and detailed answer. But it seems to me that my
problem is a lot simpler. Actually, i have an all ready CHM file, and
all what i need is a macro that refers to it and opens it as is



*** Sent via Developersdex http://www.developersdex.com ***
 
G

Gman

I guess I should have included some explanation with my response. :)

The code I posted before allows you to launch the CHM file -- as you
need. (The additional code enabled you to address specific topics within
the file. You would use that if, for example, you were implementing
context sensitive help).

Below, I've reposted the code but removed the extraneous details leaving
just that required to show a CHM file.

I've also changed it slightly so it's a function to which you just pass
the path, returning true if the launch failed.

So you would call it thus:

If not ViewHelpFile ("c:\myhelpfile.chm") then
MSGBOX "Sorry, couldn't launch the help file..."
End if

'Place at top of code module
Const HH_DISPLAY_TOPIC = &H0

Declare Function HtmlHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" _
(ByVal hwndCaller As Long, ByVal pszFile As String, _
ByVal uCommand As Long, ByVal dwData As Long) As Long

Function ViewHelpFile(myFullPath as string) as boolean
'Returns true if file was successfully launched

Dim hwndHelp As Long
Dim hWnd As Long

'The return value is the window handle of the created help window.
hwndHelp = HtmlHelp(hWnd, myFullPath, HH_DISPLAY_TOPIC, 0)
If hwndHelp > 0 then ViewHelpFile = true

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top