I am attempting to implement HTML Help into my application. I am working with a sub in a common class, in which the calling form sends its hWnd and a specific topic ID, and the help topic is shown. I also added a function to the class to call HH_CLOSE_ALL.
What I am trying to do is set up a reference to the class in any forms that need a help topic. I could set up a button or catch the F1 key to display a help topic, and then call the method to close the help when the form is unloaded.
The problem is that VB will almost always crash after I close the running application--sometimes immediately after execution ends, and sometimes it takes as much as 15 minutes before VB suddenly shows fatally shuts down.
Any thoughts on what I'm doing wrong?
I'll include a condensed version of what I am doing.
My class (clsHTMLHelp):
A form refrencing the class:Code:Option Explicit Private Const HELP_FILE = "MyHelpFile.chm" Private Const HH_HELP_CONTEXT = &HF Private Const HH_CLOSE_ALL = &H12 Private Declare Function HTMLHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" (ByVal hwnd As Long, _ ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As Long) As Long Public Sub ShowHelp(ByVal hwnd As Long, ByVal plngTopicID As Long) Dim strHelpFile As String Dim lngAPIResult As Long strHelpFile = App.Path & "\Help\" & HELP_FILE lngAPIResult = HTMLHelp(hwnd, strHelpFile, HH_HELP_CONTEXT, CLng(plngTopicID)) End Sub Public Sub ShutDownHelp(ByVal hwnd As Long) HTMLHelp hwnd, "", HH_CLOSE_ALL, CLng(0) End Sub
Code:Option Explicit Private mclsHelp As clsHTMLHelp Private Sub cmdShowHelp_Click() mclsHelp.ShowHelp Me.hwnd, 1 End Sub Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyF1 Then mclsHelp.ShowHelp Me.hwnd, 1 End If End Sub Private Sub Form_Load() Set mclsHelp = New clsHTMLHelp End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) mclsHelp.ShutDownHelp Me.hwnd Set mclsHelp = Nothing End Sub




Reply With Quote
