It should be noted that there is a better way to implement a CHM Help file into your VB 2005 application.
The easy way;
1.) Simply add your existing CHM file to your Project and set it to Copy Always or Copy If Newer.
2.) On your form, drag and drop in a HelpProvider from the Components Toolbox.
3.) In your Form Properties, adjust the setting "HelpButton" to
TRUE and adjust the setting "HelpNavigator on HelpProvider1" to
TableOfContents.
4.) Adjust the "HelpNameSpace" of the HelpProivder1 component to the name of your CHM file. ie.
MyHelpFile.chm
Done.
You can also optionally set the "HelpString" or "HelpKeyword" properties of your form, which enable you to send your user to a specific spot in your CHM, assuming you've built it correctly.
When a user presses F1 the CHM opens. This method also prevents the user from opening multiple copies of the same help document.
To create your CHM, I recommend the antiquainted but well suited
HTML Help Workshop by Microsoft. It's old, but works like a champ. Besides, the real gloss of your help file is the HTML/CSS, not the program you used to compile a CHM anyway.
The method mentioned in the previous post, while it works, would also require you capture the EventHandler of the process and track when the process exited.
However,
if you insist on doing it the hard way, here's some bonus junk;
Public WithEvents p As Process '-- Help File Process Handler
Public IsMyHelpFileOpen As Boolean = False '-- Store Current State of Help File
Public Function OpenHelp(ByVal CurrentState As Boolean) As Boolean
'-- Open the help CHM file. If already open, close it, and reopen it.
'-- Incredible Mouse
Try
If CurrentState = True Then
p.CloseMainWindow()
Else
p = New Process()
End If
' Handle the Exited event that the Process class fires.
AddHandler p.Exited, AddressOf p_Exited
p.EnableRaisingEvents = True
p.SynchronizingObject = Me
p.StartInfo.FileName = My.Application.Info.DirectoryPath & "\MyHelpFileName.chm"
p.Start()
IsMyHelpFileOpen = True
OpenHelp = True
Catch ex As Exception
OpenHelp = False
'--Write to the event log.
Dim sEvent As String
sEvent = My.Resources.HelpFileFailure
If Not EventLog.SourceExists(sSource, sMachine) Then
EventLog.CreateEventSource(mySourceData)
End If
Dim ELog As New EventLog(sLog, sMachine, sSource)
ELog.WriteEntry(sEvent, EventLogEntryType.Warning, 2001, CType(1, Short))
MsgBox("Error: " & Err.Description, MsgBoxStyle.Exclamation, "Error Encountered")
Exit Function
End Try
End Function
Private Sub p_Exited(ByVal sender As Object, ByVal e As System.EventArgs)
'-- When the CHM file is closed, this returns a false to the public variable IsMyHelpFileOpen.
IsMyHelpFileOpen = False
End Sub