Search This Blog

Wednesday, January 18, 2012

Using ShowHelp instead of HtmlHelp

My ongoing project is rewriting a database application I first wrote in MS Access 95 to VB6 and now into C#.
97% of the conversion is finally done except for the help file.

I am using HelpNDoc to author a chm help file and I was using the following VB6 code to open topics by topicID


Option Explicit

Public 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

Global Const HH_DISPLAY_TOPIC = &H0
Global Const HH_SET_WIN_TYPE = &H4
Global Const HH_GET_WIN_TYPE = &H5
Global Const HH_GET_WIN_HANDLE = &H6

' Display string resource ID or text in a popupwin.
Global Const HH_DISPLAY_TEXT_POPUP = &HE
' Display mapped numeric value in dwdata
Global Const HH_HELP_CONTEXT = &HF
' Text pop-up help, similar to WinHelp's HELP_CONTEXTMENU
Global Const HH_TP_HELP_CONTEXTMENU = &H10
' Text pop-up help, similar to WinHelp's HELP_WM_HELP
Global Const HH_TP_HELP_WM_HELP = &H11

Calling HtmlHelp:

Private Sub cmdHelp_Click()
    Call HtmlHelp(0&, gHelpFile, HH_HELP_CONTEXT, HELP_BookWindow)
End Sub

So to keep my helpfile structure I needed to be able to open help topics by topicID in C#
Here is how to call ShowHelp using topicIDs.
(Needed to invoke ToString() on the int variable to get the value to pass as an object).


public static void OpenHelp(Form currentForm, Int32 helpTopicID)
{
            try           
            {
                System.Windows.Forms.Help.ShowHelp(currentForm, _helpFile, HelpNavigator.TopicId, helpTopicID.ToString());
            }
            catch(Exception ex)
            {
                DRCCommon.Common.ErrorLog(ex);
            }
}

No comments: