LogicSmith

Cue Cards 

VB Source Code

All cue card magic begins and ends with the WinHelp API call. The prototype has changed from Windows 3.1, with all parameters now being 32-bit values.

WinHelp (hWnd AS LONG, HelpFile AS STRING, Command AS LONG, TopicID AS LONG)

When using the WinHelp API, you must explicitly close WinHelp when your application exits. This is done using the HELP_QUIT command (hex value 0002) and a topic ID of zero. We also use this command inside the routine that turns the cue cards off. The other command we use is HELP_CONTEXT (hex value 0008) to start WinHelp with our specific topic. The WinHelp API has over a dozen commands that we don't use here, so be sure to take a closer look to see what else you can do with it.

I've implemented the entire interface in one .BAS module. Since the variables it uses are module-level and declared private, I've provided several routines to set those variables, which only need to be called once at startup. Several other routines govern the display of the cue cards themselves.

SetCueCardHelpFile (HlpFile AS STRING) 
SetCueCardHwnd (hWnd AS LONG) 
SetCueDefaultTopic (TopicID AS LONG)

These three routines set default variables to be used in the WinHelp API call. The help file name should include the secondary window name (in this example, "CUECARDS.HLP>CUECARDS"). The hWnd setting could be set to any hWnd, but for this example we'll set it to the main form's hWnd. The default topic ID will be used when displaying a cue card if the passed form and control ID's are both zero. SetCueCardsOn () SetCueCardsOff () These two routines turn the cue cards on and off, and should be called from the menu's Click event for that menu item. The SetCueCardsOff routine should also be called from the main form's Unload event in case the user tries to exit with the cards enabled. ShowCueCard () This routine is the real work horse. It uses the HelpContextID's of both the active control and the active form. If the control's ID is zero, it uses the form's ID. If the form's ID is also zero (or whatever has the focus has no HelpContextID property), it uses the default topic ID input from the startup call. Put a call to this routine in the GotFocus event for every form and control where a cue card is needed.

Here's the full source code for CUECARDS.BAS:

Attribute VB_Name = "Module1" 
Option Explicit 

' Module-level variables 
Private CueDefault As Long 
Private CueHwnd As Long 
Private CueFlag As Integer 
Private CueHelpFile As String 
Private CueFirst As Integer 

' Commands to pass WinHelp() 
Public Const HELP_CONTEXT = &H1 
Public Const HELP_QUIT = &H2 
Public Const HELP_INDEX = &H3 
Public Const HELP_CONTENTS = &H3 
Public Const HELP_HELPONHELP = &H4 
Public Const HELP_SETINDEX = &H5 
Public Const HELP_SETCONTENTS = &H5 
Public Const HELP_CONTEXTPOPUP = &H8 
Public Const HELP_FORCEFILE = &H9 
Public Const HELP_KEY = &H101 
Public Const HELP_COMMAND = &H102 
Public Const HELP_PARTIALKEY = &H105 
Public Const HELP_MULTIKEY = &H201 
Public Const HELP_SETWINPOS = &H203 
Public Const HELP_FINDER = &HB 

Declare Function WinHelp Lib "user32" Alias "WinHelpA" (ByVal hwnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As Long) As Long 

Sub SetCueCardHelpFile(HlpFile As String) 
    CueHelpFile = HlpFile 
End Sub 

Sub SetCueCardHwnd(hwnd As Long) 
    CueHwnd = hwnd 
End Sub 

Sub SetCueDefaultTopic(TopicID As Long) 
    CueDefault = TopicID 
End Sub 

Sub SetCueCardsOn() 
    CueFlag = True 
    CueFirst = True 
    ShowCueCard 
End Sub 

Sub SetCueCardsOff() 
    Dim RetVal As Long 
    CueFlag = False 
    RetVal = WinHelp(CueHwnd, CueHelpFile, HELP_QUIT, 0) 
End Sub 

Sub ShowCueCard() 
    Dim RetVal As Long 
    Dim TopicID As Long 
    Dim FrmTemp As Form 
    On Error GoTo UseGeneric 
    TopicID = 0 
    If (CueFlag = True) Then 
        Set FrmTemp = Screen.ActiveForm 
        ' Get Topic ID from active control, then active form, then default 
        TopicID = Screen.ActiveForm.ActiveControl.HelpContextID 
        If (TopicID = 0) Then 
            TopicID = Screen.ActiveForm.HelpContextID 
        End If 
        If (TopicID = 0) Then 
            TopicID = CueDefault 
        End If 
        ' First time, force file, otherwise just help topic 
        If (CueFirst = True) Then 
            RetVal = WinHelp(CueHwnd, CueHelpFile, HELP_CONTEXT, TopicID) 
            DoEvents 
            RetVal = WinHelp(CueHwnd, CueHelpFile, HELP_FORCEFILE, 0) 
            CueFirst = False 
        Else 
            RetVal = WinHelp(CueHwnd, CueHelpFile, HELP_CONTEXT, TopicID) 
        End If 
        DoEvents 
        FrmTemp.SetFocus 
        DoEvents 
    End If 
    Exit Sub 
UseGeneric: 
    TopicID = 0 
    Resume Next 
End Sub

Copyright © 2009 by Dana Cline
Last Updated  Monday, April 06, 2009
Website hosted by 1and1