home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / VB98 / WIZARDS / TEMPLATE / WIZARD.BAS < prev    next >
Encoding:
BASIC Source File  |  1998-06-18  |  7.0 KB  |  219 lines

  1. Attribute VB_Name = "modWizard"
  2. Option Explicit
  3.  
  4. Global Const WIZARD_NAME = "WizardTemplate"
  5.  
  6. Declare Function WritePrivateProfileString& Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal AppName$, ByVal KeyName$, ByVal keydefault$, ByVal FileName$)
  7.  
  8. 'WinHelp Commands
  9. 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
  10. Public Const HELP_QUIT = &H2              '  Terminate help
  11. Public Const HELP_CONTENTS = &H3&         '  Display index/contents
  12. Public Const HELP_CONTEXT = &H1           '  Display topic in ulTopic
  13. Public Const HELP_INDEX = &H3             '  Display index
  14.  
  15. Global Const APP_CATEGORY = "Wizards"
  16.  
  17. Global Const CONFIRM_KEY = "ConfirmScreen"
  18. Global Const DONTSHOW_CONFIRM = "DontShow"
  19.  
  20.  
  21. '--------------------------------------------------------------------------
  22. 'this sub must be executed from the  immediate window
  23. 'it will add the entry to VBADDIN.INI if it doesn't already exist
  24. 'so that the add-in is on available next time VB is loaded
  25. '--------------------------------------------------------------------------
  26. Sub AddToINI()
  27.     Debug.Print WritePrivateProfileString("Add-Ins32", WIZARD_NAME & ".Wizard", "0", "VBADDIN.INI")
  28. End Sub
  29.  
  30. Function GetResString(nRes As Integer) As String
  31.     Dim sTmp As String
  32.     Dim sRetStr As String
  33.   
  34.     Do
  35.         sTmp = LoadResString(nRes)
  36.         If Right(sTmp, 1) = "_" Then
  37.             sRetStr = sRetStr + VBA.Left(sTmp, Len(sTmp) - 1)
  38.         Else
  39.             sRetStr = sRetStr + sTmp
  40.         End If
  41.         nRes = nRes + 1
  42.     Loop Until Right(sTmp, 1) <> "_"
  43.     GetResString = sRetStr
  44.   
  45. End Function
  46.  
  47. Function GetField(sBuffer As String, sSep As String) As String
  48.     Dim p As Integer
  49.     
  50.     p = InStr(sBuffer & sSep, sSep)
  51.     GetField = VBA.Left(sBuffer, p - 1)
  52.     sBuffer = Mid(sBuffer, p + Len(sSep))
  53.   
  54. End Function
  55.  
  56. Sub LoadResStrings(frm As Form)
  57.     On Error Resume Next
  58.     
  59.     Dim ctl As Control
  60.     Dim obj As Object
  61.     
  62.     'set the form's caption
  63.     If IsNumeric(frm.Tag) Then
  64.         frm.Caption = LoadResString(CInt(frm.Tag))
  65.     End If
  66.     
  67.     'set the controls' captions using the caption
  68.     'property for menu items and the Tag property
  69.     'for all other controls
  70.     For Each ctl In frm.Controls
  71.         If TypeName(ctl) = "Menu" Then
  72.             If IsNumeric(ctl.Caption) Then
  73.                 If Err = 0 Then
  74.                     ctl.Caption = LoadResString(CInt(ctl.Caption))
  75.                 Else
  76.                     Err = 0
  77.                 End If
  78.             End If
  79.         ElseIf TypeName(ctl) = "TabStrip" Then
  80.             For Each obj In ctl.Tabs
  81.                 If IsNumeric(obj.Tag) Then
  82.                     obj.Caption = LoadResString(CInt(obj.Tag))
  83.                 End If
  84.                 'check for a tooltip
  85.                 If IsNumeric(obj.ToolTipText) Then
  86.                     If Err = 0 Then
  87.                         obj.ToolTipText = LoadResString(CInt(obj.ToolTipText))
  88.                     Else
  89.                         Err = 0
  90.                     End If
  91.                 End If
  92.             Next
  93.         ElseIf TypeName(ctl) = "Toolbar" Then
  94.             For Each obj In ctl.Buttons
  95.                 If IsNumeric(obj.Tag) Then
  96.                     obj.ToolTipText = LoadResString(CInt(obj.Tag))
  97.                 End If
  98.             Next
  99.         ElseIf TypeName(ctl) = "ListView" Then
  100.             For Each obj In ctl.ColumnHeaders
  101.                 If IsNumeric(obj.Tag) Then
  102.                     obj.Text = LoadResString(CInt(obj.Tag))
  103.                 End If
  104.             Next
  105.         Else
  106.             If IsNumeric(ctl.Tag) Then
  107.                 If Err = 0 Then
  108.                     ctl.Caption = GetResString(CInt(ctl.Tag))
  109.                 Else
  110.                     Err = 0
  111.                 End If
  112.             End If
  113.             'check for a tooltip
  114.             If IsNumeric(ctl.ToolTipText) Then
  115.                 If Err = 0 Then
  116.                     ctl.ToolTipText = LoadResString(CInt(ctl.ToolTipText))
  117.                 Else
  118.                     Err = 0
  119.                 End If
  120.             End If
  121.         End If
  122.     Next
  123.  
  124. End Sub
  125.  
  126. '==================================================
  127. 'Purpose: Replace the <TOPIC_TEXT> string(s) in
  128. '         res file string for correct placement
  129. '         of localized tokens
  130. '
  131. 'Inputs:  sString = String to search and replace in
  132. '         sReplacement = String to replace token with
  133. '         sReplacement2 = 2nd String to replace token with
  134. '
  135. 'Outputs: New string with token replaced throughout
  136. '==================================================
  137. Function ReplaceTopicTokens(sString As String, _
  138.                             sReplacement As String, _
  139.                             sReplacement2 As String) As String
  140.     On Error Resume Next
  141.     
  142.     Dim p As Integer
  143.     Dim sTmp As String
  144.     
  145.     Const TOPIC_TEXT = "<TOPIC_TEXT>"
  146.     Const TOPIC_TEXT2 = "<TOPIC_TEXT2>"
  147.     
  148.     sTmp = sString
  149.     Do
  150.         p = InStr(sTmp, TOPIC_TEXT)
  151.         If p Then
  152.             sTmp = VBA.Left(sTmp, p - 1) + sReplacement + Mid(sTmp, p + Len(TOPIC_TEXT))
  153.         End If
  154.     Loop While p
  155.     
  156.     If Len(sReplacement2) > 0 Then
  157.         Do
  158.             p = InStr(sTmp, TOPIC_TEXT2)
  159.             If p Then
  160.                 sTmp = VBA.Left(sTmp, p - 1) + sReplacement2 + Mid(sTmp, p + Len(TOPIC_TEXT2))
  161.             End If
  162.         Loop While p
  163.     End If
  164.     
  165.     ReplaceTopicTokens = sTmp
  166.   
  167. End Function
  168.  
  169. Public Function GetResData(sResName As String, sResType As String) As String
  170.     Dim sTemp As String
  171.     Dim p As Integer
  172.   
  173.     sTemp = StrConv(LoadResData(sResName, sResType), vbUnicode)
  174.     p = InStr(sTemp, vbNullChar)
  175.     If p Then sTemp = VBA.Left$(sTemp, p - 1)
  176.     GetResData = sTemp
  177. End Function
  178.  
  179. Function AddToAddInCommandBar(VBInst As Object, sCaption As String, oBitmap As Object) As Object   'Office.CommandBarControl
  180.     On Error GoTo AddToAddInCommandBarErr
  181.     
  182.     Dim c As Integer
  183.     Dim cbMenuCommandBar As Object   'Office.CommandBarControl  'command bar object
  184.     Dim cbMenu As Object
  185.     
  186.     'see if we can find the Add-Ins menu
  187.     Set cbMenu = VBInst.CommandBars("Add-Ins")
  188.     If cbMenu Is Nothing Then
  189.         'not available so we fail
  190.         Exit Function
  191.     End If
  192.     
  193.     'add it to the command bar
  194.     Set cbMenuCommandBar = cbMenu.Controls.Add(1)
  195.     c = cbMenu.Controls.Count - 1
  196.     If cbMenu.Controls(c).BeginGroup And _
  197.         Not cbMenu.Controls(c - 1).BeginGroup Then
  198.         'this s the first addin being added so it needs a separator
  199.         cbMenuCommandBar.BeginGroup = True
  200.     End If
  201.     'set the caption
  202.     cbMenuCommandBar.Caption = sCaption
  203.     'undone:set the onaction (required at this point)
  204.     cbMenuCommandBar.OnAction = "hello"
  205.     'copy the icon to the clipboard
  206.     Clipboard.SetData oBitmap
  207.     'set the icon for the button
  208.     cbMenuCommandBar.PasteFace
  209.   
  210.     Set AddToAddInCommandBar = cbMenuCommandBar
  211.     
  212.     Exit Function
  213. AddToAddInCommandBarErr:
  214.   
  215. End Function
  216.  
  217.  
  218.  
  219.