Home WinHelp HTML Help MS Help 2.0 LongHorn Help Store Links Betas Projects  
 

HTML Help Training Cards for VB5/6
October 22, 2000

  Download The Sample Project Here (6k)

This is another one of those nagging questions. Not that I get nagged with this question, but it sure does come up a lot! "How do I use Training Cards with Visual Basic?" The information on the answer has always seemed sketchy, and for quite a while, I said it couldn't be done. Back in August, in a quiet pre-morning programming session at a resort in Branson, Missouri, the solution finally dawned on me. It's so simple, I don't know why I didn't see it before.

Ok, here's the scoop: Use Mabry's MsgHook for the subclassing. You can download a copy at the bottom of the Projects section. You don't use it to subclass the HTML Help window, but rather the Visual Basic form itself.

The code in the HTML file in the CHM looks like the following. Please read the comments I've included here:

<html>

<head>
<title></title>
</head>

<body>

<p><!--

The following code has been modified from what the wizard in the HTML Help Workshop generates. The original code was:

<object id="tcardtest" type="application/x-oleobject"
classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"
width="14" height="14">
<param name="Command" value="TCard">
<param name="Item1" value="10040">
<param name="Item2" value="12345">
</object>

Note how, in the modified version there is now only one Item param instead of two, and the sizes are now zero ("0"). The Item modification is due to a bug in the HTML Help Workshop ActiveX control wizard. The size modifications are so the object takes up less room on the page.

--> 
<object id="tcardtest" type="application/x-oleobject"
classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" width="0" height="0">
<param name="Command" value="TCard">
<param name="Item1" value="10040,12345">
</object>
</p>

<p>Click <a href="javascript:tcardtest.Click();">here</a> to see an event caused by a WM_TCARD message. (Note: The WM_TCARD message will only work if a CHM is opened from an app using the form's handle to show ownership.)</p>

</body>
</html>


The Visual Basic code is rather simple itself, and depends on the MsgHook control for its entire operation. The Msghook1_Message Sub will be available automatically once you add the MsgHook control to the form:

Option Explicit

Private Const WM_TCARD = &H52&

Private Const HH_DISPLAY_TOPIC = &H0

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

Private Sub Form_Load()

  ' Set up subclassing so we can snag the
  ' WM_TCARD message for this form
  Msghook1.HwndHook = Me.hwnd
  Msghook1.Message(WM_TCARD) = True

End Sub

Private Sub cmdOpenCHM_Click()

  ' In order for the WM_TCARD message to work, the
  ' app must own the instance of the HTML Help window.
  HTMLHelp Me.hwnd, App.Path & "\VBT_Card.chm", _
      HH_DISPLAY_TOPIC, 0

End Sub

Private Sub Msghook1_Message(ByVal msg As Long, _
    ByVal wp As Long, _
    ByVal lp As Long, _
    result As Long)

  Select Case msg
  Case WM_TCARD
    Select Case wp
    Case 10040
      ' It's intended for this form, so
      ' check to see what to do
      Select Case lp
      Case 12345
        MsgBox "This is where the correct code would be run.", _
            vbOKOnly + vbInformation, "WM_TCARD Test"
      End Select
    End Select
  End Select ' msg

End Sub