home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / sgwnd10 / frmselec.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-08-10  |  26.8 KB  |  821 lines

  1. VERSION 5.00
  2. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "COMCTL32.OCX"
  3. Begin VB.Form frmWizard 
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "Stinga sgWindow Wizard"
  6.    ClientHeight    =   5484
  7.    ClientLeft      =   2172
  8.    ClientTop       =   1932
  9.    ClientWidth     =   6912
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   5484
  14.    ScaleWidth      =   6912
  15.    ShowInTaskbar   =   0   'False
  16.    StartUpPosition =   2  'CenterScreen
  17.    Begin VB.Frame fraStep 
  18.       BorderStyle     =   0  'None
  19.       Caption         =   "Select sgWindow Object Name"
  20.       Enabled         =   0   'False
  21.       Height          =   2016
  22.       Index           =   3
  23.       Left            =   -10000
  24.       TabIndex        =   19
  25.       Top             =   972
  26.       Width           =   4968
  27.       Begin VB.ListBox lstHandlers 
  28.          Height          =   1776
  29.          Left            =   0
  30.          TabIndex        =   20
  31.          Top             =   0
  32.          Width           =   2928
  33.       End
  34.    End
  35.    Begin VB.Frame fraStep 
  36.       BorderStyle     =   0  'None
  37.       Caption         =   "Finish"
  38.       Enabled         =   0   'False
  39.       Height          =   1448
  40.       Index           =   4
  41.       Left            =   -10000
  42.       TabIndex        =   18
  43.       Top             =   1920
  44.       Width           =   4896
  45.       Begin VB.Label Label1 
  46.          Caption         =   "To find wizard generated code search code module for text 'SGWindow Wizard'"
  47.          BeginProperty Font 
  48.             Name            =   "Arial"
  49.             Size            =   10.2
  50.             Charset         =   0
  51.             Weight          =   400
  52.             Underline       =   0   'False
  53.             Italic          =   0   'False
  54.             Strikethrough   =   0   'False
  55.          EndProperty
  56.          Height          =   792
  57.          Left            =   0
  58.          TabIndex        =   22
  59.          Top             =   0
  60.          Width           =   4788
  61.          WordWrap        =   -1  'True
  62.       End
  63.    End
  64.    Begin VB.Frame fraStep 
  65.       BorderStyle     =   0  'None
  66.       Caption         =   "Select Message(s)"
  67.       Enabled         =   0   'False
  68.       Height          =   2448
  69.       Index           =   2
  70.       Left            =   -10000
  71.       TabIndex        =   9
  72.       Top             =   1080
  73.       Width           =   5112
  74.       Begin VB.ListBox lstMessages 
  75.          Height          =   2160
  76.          Index           =   1
  77.          Left            =   1836
  78.          MultiSelect     =   2  'Extended
  79.          TabIndex        =   16
  80.          Top             =   36
  81.          Width           =   3252
  82.       End
  83.       Begin VB.ListBox lstMessages 
  84.          Height          =   2160
  85.          Index           =   0
  86.          Left            =   1836
  87.          TabIndex        =   15
  88.          Top             =   36
  89.          Width           =   3252
  90.       End
  91.       Begin VB.OptionButton optTemplate 
  92.          Caption         =   "Predefined template"
  93.          Height          =   264
  94.          Left            =   0
  95.          TabIndex        =   14
  96.          Top             =   1008
  97.          Width           =   1884
  98.       End
  99.       Begin VB.OptionButton optRange 
  100.          Caption         =   "Message &range"
  101.          Height          =   264
  102.          Left            =   0
  103.          TabIndex        =   13
  104.          Top             =   522
  105.          Width           =   1812
  106.       End
  107.       Begin VB.OptionButton optMessage 
  108.          Caption         =   "Single &message"
  109.          Height          =   264
  110.          Left            =   0
  111.          TabIndex        =   12
  112.          Top             =   36
  113.          Width           =   1812
  114.       End
  115.       Begin VB.Label lblMsgDescription 
  116.          Height          =   192
  117.          Left            =   108
  118.          TabIndex        =   17
  119.          Top             =   2232
  120.          Width           =   4764
  121.       End
  122.    End
  123.    Begin VB.Frame fraStep 
  124.       BorderStyle     =   0  'None
  125.       Caption         =   "Welcome"
  126.       Enabled         =   0   'False
  127.       Height          =   1416
  128.       Index           =   0
  129.       Left            =   1560
  130.       TabIndex        =   7
  131.       Top             =   1680
  132.       Width           =   4968
  133.    End
  134.    Begin VB.Frame fraStep 
  135.       BorderStyle     =   0  'None
  136.       Caption         =   "Select Window"
  137.       Enabled         =   0   'False
  138.       Height          =   2628
  139.       Index           =   1
  140.       Left            =   -10000
  141.       TabIndex        =   8
  142.       Top             =   900
  143.       Width           =   5112
  144.       Begin ComctlLib.TreeView tvwControls 
  145.          Height          =   2568
  146.          Left            =   0
  147.          TabIndex        =   10
  148.          Top             =   0
  149.          Width           =   5088
  150.          _ExtentX        =   8975
  151.          _ExtentY        =   4530
  152.          _Version        =   327682
  153.          HideSelection   =   0   'False
  154.          Indentation     =   423
  155.          LabelEdit       =   1
  156.          LineStyle       =   1
  157.          Style           =   7
  158.          Appearance      =   1
  159.       End
  160.    End
  161.    Begin VB.Frame frmSeparator 
  162.       Height          =   72
  163.       Left            =   108
  164.       TabIndex        =   6
  165.       Top             =   4716
  166.       Width           =   6672
  167.    End
  168.    Begin VB.CommandButton cmdBack 
  169.       Caption         =   "< &Back"
  170.       Height          =   372
  171.       Left            =   3420
  172.       TabIndex        =   2
  173.       Top             =   4968
  174.       Width           =   1068
  175.    End
  176.    Begin VB.CommandButton cmdCancel 
  177.       Caption         =   "&Cancel"
  178.       Height          =   372
  179.       Left            =   5688
  180.       TabIndex        =   4
  181.       Top             =   4968
  182.       Width           =   1068
  183.    End
  184.    Begin VB.CommandButton cmdNext 
  185.       Caption         =   "&Next >"
  186.       Height          =   372
  187.       Left            =   4500
  188.       TabIndex        =   3
  189.       Top             =   4968
  190.       Width           =   1068
  191.    End
  192.    Begin VB.Image Image1 
  193.       BorderStyle     =   1  'Fixed Single
  194.       Enabled         =   0   'False
  195.       Height          =   4428
  196.       Left            =   144
  197.       Picture         =   "frmSelectWindow.frx":0000
  198.       Stretch         =   -1  'True
  199.       Top             =   180
  200.       Width           =   1284
  201.    End
  202.    Begin ComctlLib.ImageList ImageList1 
  203.       Left            =   5400
  204.       Top             =   4932
  205.       _ExtentX        =   804
  206.       _ExtentY        =   804
  207.       BackColor       =   -2147483643
  208.       ImageWidth      =   16
  209.       ImageHeight     =   15
  210.       MaskColor       =   12632256
  211.       _Version        =   327682
  212.       BeginProperty Images {0713E8C2-850A-101B-AFC0-4210102A8DA7} 
  213.          NumListImages   =   2
  214.          BeginProperty ListImage1 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  215.             Picture         =   "frmSelectWindow.frx":364C
  216.             Key             =   ""
  217.          EndProperty
  218.          BeginProperty ListImage2 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  219.             Picture         =   "frmSelectWindow.frx":3756
  220.             Key             =   ""
  221.          EndProperty
  222.       EndProperty
  223.    End
  224.    Begin VB.Label lblMessage 
  225.       Caption         =   "Message text"
  226.       BeginProperty Font 
  227.          Name            =   "Arial"
  228.          Size            =   10.2
  229.          Charset         =   0
  230.          Weight          =   700
  231.          Underline       =   0   'False
  232.          Italic          =   0   'False
  233.          Strikethrough   =   0   'False
  234.       EndProperty
  235.       Height          =   480
  236.       Left            =   144
  237.       TabIndex        =   11
  238.       Top             =   4932
  239.       Width           =   3000
  240.    End
  241.    Begin VB.Label lblDescription 
  242.       Caption         =   "Page description"
  243.       BeginProperty Font 
  244.          Name            =   "Arial"
  245.          Size            =   9
  246.          Charset         =   0
  247.          Weight          =   400
  248.          Underline       =   0   'False
  249.          Italic          =   0   'False
  250.          Strikethrough   =   0   'False
  251.       EndProperty
  252.       Height          =   1128
  253.       Left            =   1600
  254.       TabIndex        =   1
  255.       Top             =   612
  256.       Width           =   5052
  257.    End
  258.    Begin VB.Label lblWizardState 
  259.       BackColor       =   &H80000005&
  260.       Caption         =   "description"
  261.       BeginProperty Font 
  262.          Name            =   "Arial"
  263.          Size            =   9
  264.          Charset         =   0
  265.          Weight          =   400
  266.          Underline       =   0   'False
  267.          Italic          =   0   'False
  268.          Strikethrough   =   0   'False
  269.       EndProperty
  270.       Height          =   876
  271.       Left            =   1668
  272.       TabIndex        =   5
  273.       Top             =   3672
  274.       Width           =   5016
  275.    End
  276.    Begin VB.Label lblTitle 
  277.       Caption         =   "Page Title"
  278.       BeginProperty Font 
  279.          Name            =   "Arial"
  280.          Size            =   18
  281.          Charset         =   0
  282.          Weight          =   700
  283.          Underline       =   0   'False
  284.          Italic          =   -1  'True
  285.          Strikethrough   =   0   'False
  286.       EndProperty
  287.       Height          =   408
  288.       Left            =   1600
  289.       TabIndex        =   0
  290.       Top             =   144
  291.       Width           =   4836
  292.    End
  293.    Begin VB.Label lblWizardState2 
  294.       BackColor       =   &H80000005&
  295.       BorderStyle     =   1  'Fixed Single
  296.       BeginProperty Font 
  297.          Name            =   "Arial"
  298.          Size            =   9
  299.          Charset         =   0
  300.          Weight          =   400
  301.          Underline       =   0   'False
  302.          Italic          =   0   'False
  303.          Strikethrough   =   0   'False
  304.       EndProperty
  305.       Height          =   948
  306.       Left            =   1596
  307.       TabIndex        =   21
  308.       Top             =   3636
  309.       Width           =   5124
  310.    End
  311. Attribute VB_Name = "frmWizard"
  312. Attribute VB_GlobalNameSpace = False
  313. Attribute VB_Creatable = False
  314. Attribute VB_PredeclaredId = True
  315. Attribute VB_Exposed = False
  316. '--------------------------------------------------------------------------
  317. ' File: FRMSELECTWINDOW.FRM
  318. ' This file is part of the 'Stinga sgWindow Wizard' project.
  319. ' Copyright (C) 1998 Stinga
  320. ' All rights reserved.
  321. '--------------------------------------------------------------------------
  322. Option Explicit
  323. Public VBInstance As VBIDE.VBE
  324. Public Connect As Connect
  325. Const NUM_STEPS = 5
  326. Const HELP_BASE = 1000
  327. Const HELP_FILE = ""
  328. Const BTN_HELP = 0
  329. Const BTN_CANCEL = 1
  330. Const BTN_BACK = 2
  331. Const BTN_NEXT = 3
  332. Const BTN_FINISH = 4
  333. Const STEP_INTRO = 0
  334. Const STEP_1 = 1
  335. Const STEP_2 = 2
  336. Const STEP_3 = 3
  337. Const STEP_FINISH = 4
  338. Const DIR_NONE = 0
  339. Const DIR_BACK = 1
  340. Const DIR_NEXT = 2
  341. Const FRM_TITLE = "Stinga sgWindow Wizard"
  342. Const sDefaultHandler = "Default handler (mWnd)"
  343. Public mnCurStep    As Integer
  344. Dim mbFinishOK      As Boolean
  345. ' Description strings
  346. Dim sTitles() As String
  347. Dim sDescriptions() As String
  348. ' Wizard template class
  349. Public Template As sgWindowTemplate
  350. Public Sub Clear()
  351.     Template.Clear
  352.     lstMessages(0).Clear
  353.     lstMessages(1).Clear
  354.     optMessage.Value = False
  355.     optRange.Value = False
  356.     optTemplate.Value = False
  357. End Sub
  358. '-----------------------------------------------------------------------
  359. ' Helper functions
  360. '-----------------------------------------------------------------------
  361. Private Sub FillMessages(lst As ListBox)
  362.     On Error GoTo Error_
  363.     lst.Clear
  364.     lst.ZOrder 0
  365.     Dim mi As MemberInfo
  366.     For Each mi In Template.TypeLib.TypeInfos.NamedItem("WinMsg").Members
  367.         lst.AddItem UCase(mi.name)
  368.         lst.ItemData(lst.NewIndex) = mi.Value
  369.     Next
  370.     Exit Sub
  371. Error_:
  372.     MsgBox Error$
  373. End Sub
  374. Private Sub FillTemplates(lst As ListBox)
  375.     lst.Clear
  376.     lst.ZOrder 0
  377.     Dim sFileName As String
  378.     sFileName = Dir(VBInstance.TemplatePath + "/SGWindow/*.swt")
  379.     Do Until Len(sFileName) = 0
  380.         lst.AddItem sFileName
  381.         sFileName = Dir
  382.     Loop
  383. End Sub
  384. Private Sub FillHandlers(lst As ListBox)
  385.     lst.Clear
  386.     ' Add default window handler
  387.     lst.AddItem sDefaultHandler
  388.     If (Template.HandlerName = "mWnd") Then
  389.         lst.Selected(0) = True
  390.     End If
  391.     ' Parse code module and extract all sgWindow objects
  392.     If (Template.FormName <> "") Then
  393.         Dim proj As VBProject
  394.         Dim formCode As CodeModule
  395.         Set proj = VBInstance.VBProjects.StartProject
  396.         Set formCode = proj.VBComponents(Template.FormName).CodeModule
  397.         
  398.         Dim m As Member
  399.         For Each m In formCode.Members
  400.             If m.Type = vbext_mt_Variable Then
  401.                 Dim sLine$
  402.                 sLine = formCode.Lines(m.CodeLocation, 1)
  403.                 If (InStr(sLine, "WithEvents") > 0) And (InStr(sLine, "Window") > 0) Then
  404.                     lst.AddItem m.name
  405.                     If (m.name = Template.HandlerName) Then
  406.                         lst.Selected(lst.NewIndex) = True
  407.                     End If
  408.                 End If
  409.             End If
  410.         Next
  411.     End If
  412. End Sub
  413. Private Sub FillControlsTree(tv As TreeView)
  414.     Dim el As Object
  415.     Dim nodForm As Node
  416.     tv.Nodes.Clear
  417.     tv.ImageList = ImageList1
  418.     Dim proj As VBProject
  419.     If VBInstance.VBProjects.Count > 0 Then
  420.       Set proj = VBInstance.VBProjects.StartProject
  421.       For Each el In proj.VBComponents
  422.           If el.Type = vbext_ct_VBForm Then
  423.               Set nodForm = tv.Nodes.Add(, , , el.name, 1)
  424.               nodForm.Tag = "Form;" & el.name
  425.               If (Template.FormName = el.name) Then
  426.                   nodForm.Selected = True
  427.                   nodForm.EnsureVisible
  428.               End If
  429.               AddControls tv, nodForm, el.name
  430.           End If
  431.       Next
  432.    End If
  433. End Sub
  434. Private Sub AddControls(tv As TreeView, nodForm As Node, sFormName$)
  435.     Dim ctl As VBControl
  436.     Dim nodControl As Node
  437.     Dim StartProj As VBProject
  438.     Set StartProj = VBInstance.VBProjects.StartProject
  439.     Dim Form As VBForm
  440.     Set Form = StartProj.VBComponents(sFormName).Designer
  441.     For Each ctl In Form.ContainedVBControls
  442.         ' Get current control
  443.         Dim ctlObj As Object
  444.         Set ctlObj = ctl.ControlObject
  445.         
  446.         ' We are using controls with HWND
  447.         On Error Resume Next
  448.         Dim hwnd As Long
  449.         hwnd = ctlObj.hwnd
  450.         If Err = 0 Then
  451.             Set nodControl = tv.Nodes.Add(nodForm, tvwChild, , ctlObj.name & " (" & ctl.ClassName & ")", 2)
  452.             nodControl.Tag = "Control;" & sFormName & ";" & ctlObj.name
  453.             If (Template.ControlName = ctlObj.name) Then
  454.                 nodControl.Selected = True
  455.                 nodControl.EnsureVisible
  456.             End If
  457.         End If
  458.     Next
  459. End Sub
  460. Public Sub SetStep(nStep As Integer, nDirection As Integer)
  461.     If nStep > mnCurStep Then
  462.         If Not OnNextPage(mnCurStep, nStep) Then Exit Sub
  463.     Else
  464.         If Not OnBackPage(mnCurStep, nStep) Then Exit Sub
  465.     End If
  466.     Select Case nStep
  467.         Case STEP_INTRO
  468.             fraStep(nStep).Top = 1800
  469.       
  470.         Case STEP_1
  471.             fraStep(nStep).Top = 950
  472.       
  473.         Case STEP_2
  474.             fraStep(nStep).Top = 1300
  475.         
  476.         Case STEP_3
  477.             fraStep(nStep).Top = 1000
  478.             
  479.         Case STEP_FINISH
  480.             fraStep(nStep).Top = 1700
  481.             mbFinishOK = True
  482.         
  483.         Case Else
  484.             ' Invalid page
  485.             Exit Sub
  486.     End Select
  487.     ' Move to new step
  488.     fraStep(mnCurStep).Enabled = False
  489.     fraStep(nStep).Left = 1600
  490.     Dim h%
  491.     h = lblWizardState.Top - fraStep(nStep).Top - 60
  492.     If (h < 0) Then h = 100
  493.     fraStep(nStep).Height = h
  494.     lblDescription.ZOrder 0
  495.     If nStep <> mnCurStep Then
  496.         fraStep(mnCurStep).Top = -10000
  497.         fraStep(mnCurStep).Left = -10000
  498.     End If
  499.     fraStep(nStep).Enabled = True
  500.     SetTitles nStep
  501.     SetNavBtns nStep
  502.     mnCurStep = nStep
  503.     OnPageOpen mnCurStep
  504.     EnableNavControls mnCurStep
  505.     ' Update description
  506.     lblWizardState = Template.DescriptionText
  507. End Sub
  508. Private Sub SetTitles(nStep As Integer)
  509.     On Error Resume Next
  510.     Me.Caption = sTitles(nStep) & " - " & FRM_TITLE
  511.     lblTitle = sTitles(nStep)
  512.     lblDescription = sDescriptions(nStep)
  513. End Sub
  514. Private Sub SetNavBtns(nStep As Integer)
  515.     mnCurStep = nStep
  516.     If mnCurStep = 0 Then
  517.         cmdNext.Caption = "&Next >"
  518.         cmdBack.Enabled = False
  519.         cmdNext.Enabled = True
  520.     ElseIf mnCurStep = NUM_STEPS - 1 Then
  521.         cmdNext.Caption = "&Finish"
  522.         cmdNext.Enabled = False
  523.         cmdBack.Enabled = True
  524.     Else
  525.         cmdNext.Caption = "&Next >"
  526.         cmdBack.Enabled = True
  527.         cmdNext.Enabled = True
  528.     End If
  529.     If mbFinishOK Then
  530.         cmdNext.Enabled = True
  531.     Else
  532.         cmdNext.Enabled = True
  533.     End If
  534. End Sub
  535. Private Function OnPageOpen(nPage%) As Boolean
  536.     OnPageOpen = True
  537.     lblWizardState.Visible = True
  538.     lblWizardState2.Visible = True
  539.     Select Case nPage
  540.         Case STEP_INTRO
  541.             lblWizardState.Visible = False
  542.             lblWizardState2.Visible = False
  543.       
  544.         Case STEP_1
  545.             Me.MousePointer = vbHourglass
  546.             lblMessage.Caption = "Parsing start up project..."
  547.             FillControlsTree tvwControls
  548.             lblMessage.Caption = ""
  549.             Me.MousePointer = vbArrow
  550.       
  551.         Case STEP_2
  552.         
  553.         Case STEP_3
  554.             FillHandlers lstHandlers
  555.             
  556.         Case STEP_FINISH
  557.         
  558.         Case Else
  559.             ' Invalid page
  560.     End Select
  561. End Function
  562. Private Function OnBackPage(nCurrPage%, nNewPage%) As Boolean
  563.     OnBackPage = True
  564.     Select Case nCurrPage
  565.         Case STEP_INTRO
  566.         
  567.         Case STEP_1
  568.         
  569.         Case STEP_2
  570.         
  571.         Case STEP_3
  572.         
  573.         Case STEP_FINISH
  574.         
  575.         Case Else
  576.             ' Invalid page
  577.     End Select
  578. End Function
  579. Private Function OnNextPage(nCurrPage%, nNewPage%) As Boolean
  580.     OnNextPage = True
  581.     Select Case nCurrPage
  582.         Case STEP_INTRO
  583.       
  584.         Case STEP_1
  585.             ' Can not go to the next page if no window is selected
  586.             If (Template.FormName = "") And (Template.ControlName = "") Then
  587.                 OnNextPage = False
  588.             End If
  589.       
  590.         Case STEP_2
  591.             ' Can not go to the next page if tehere is
  592.             ' no message or template file selected
  593.             If optMessage.Value Or optRange.Value Then
  594.                 If (Template.FirstMessage = wm_NULL) Then OnNextPage = False
  595.             ElseIf optTemplate.Value Then
  596.                 If Template.TemplateFile = "" Then OnNextPage = False
  597.             End If
  598.         
  599.         Case STEP_3
  600.             ' Can not go to the next page if no handler is selected
  601.             If (Template.HandlerName = "") Then
  602.                 OnNextPage = False
  603.             End If
  604.             
  605.         Case STEP_FINISH
  606.         
  607.         Case Else
  608.             ' Invalid page
  609.     End Select
  610. End Function
  611. Private Sub EnableNavControls(nPage%)
  612.     cmdBack.Enabled = True
  613.     cmdNext.Enabled = True
  614.     Select Case nPage
  615.         Case STEP_INTRO
  616.             cmdBack.Enabled = False
  617.       
  618.         Case STEP_1
  619.             If (Template.FormName = "") And (Template.ControlName = "") Then
  620.                 cmdNext.Enabled = False
  621.             End If
  622.       
  623.         Case STEP_2
  624.             If optMessage.Value Or optRange.Value Then
  625.                 If (Template.FirstMessage = wm_NULL) Then
  626.                     cmdNext.Enabled = False
  627.                 End If
  628.             ElseIf optTemplate.Value Then
  629.                 If Template.TemplateFile = "" Then
  630.                     cmdNext.Enabled = False
  631.                 End If
  632.             End If
  633.         
  634.         Case STEP_3
  635.             If (Template.HandlerName = "") Then
  636.                 cmdNext.Enabled = False
  637.             End If
  638.             
  639.         Case STEP_FINISH
  640.         
  641.         Case Else
  642.             ' Invalid page
  643.     End Select
  644. End Sub
  645. '-----------------------------------------------------------------------
  646. ' Form event handlers
  647. '-----------------------------------------------------------------------
  648. Private Sub Form_Load()
  649.     On Error GoTo Error_
  650.     Set Template = New sgWindowTemplate
  651.     mbFinishOK = False
  652.     Dim i%
  653.     For i = 0 To NUM_STEPS - 1
  654.       fraStep(i).Left = -10000
  655.     Next
  656.     ' Initialize titles and descriptions
  657.     ReDim sTitles(NUM_STEPS) As String
  658.     ReDim sDescriptions(NUM_STEPS) As String
  659.     sTitles(0) = "Welcome!"
  660.     sDescriptions(0) = "Welcome to the sgWindow Wizard!" + vbCrLf + vbCrLf + _
  661.                        "This wizard enables you to use advanced programming techniques with allmost no effort. Just answer few simple questions and you will be able to subclass any window."
  662.     sTitles(1) = "Select Window Handle"
  663.     sDescriptions(1) = "Select form or control you want to subclass."
  664.     sTitles(2) = "Select Message(s)"
  665.     sDescriptions(2) = "Select message or message range you want to handle." + vbCrLf + _
  666.                        "If you select message handler template, wizard will insert predefined template into your code."
  667.     sTitles(3) = "Select Handler Name"
  668.     sDescriptions(3) = "Select message handler variable."
  669.     sTitles(4) = "Finish!"
  670.     sDescriptions(4) = "Press finish and sgWindow wizard will insert message handler into your application."
  671.     SetStep 0, DIR_NONE
  672.     lblMessage.Caption = ""
  673.     Exit Sub
  674. Error_:
  675.     MsgBox Error$
  676. End Sub
  677. Private Sub cmdBack_Click()
  678.     SetStep mnCurStep - 1, DIR_NONE
  679. End Sub
  680. Private Sub cmdNext_Click()
  681.     On Error GoTo Error_
  682.     If mnCurStep = (NUM_STEPS - 1) Then
  683.         ' Finish
  684.         If (Template.FormName <> "") Then
  685.             Dim code As CodeModule
  686.             Set code = VBInstance.VBProjects.StartProject.VBComponents(Template.FormName).CodeModule
  687.             
  688.             ' Make sure that SGWindow is referenced in the active project
  689. '            On Error Resume Next
  690. '            If Not IsSGWindowReferenced Then
  691. '              MsgBox "SG Window is not referenced!" & vbCrLf & _
  692. '                     "Open Project menu and click on the References... command to add SG Window to the list of the referenced components"
  693. '              Exit Sub
  694. '            End If
  695.             On Error GoTo Error_
  696.             If Not Template.UpdateCodeModule(code, Template.FormName) Then
  697.                 MsgBox "Code insertion failed!", vbOKOnly, "SG Window Wizard"
  698.             End If
  699.         End If
  700.         Me.Hide
  701.     Else
  702.         ' Next page
  703.         SetStep mnCurStep + 1, DIR_NONE
  704.     End If
  705.     Exit Sub
  706. Error_:
  707.     MsgBox Error$
  708. End Sub
  709. Private Sub cmdCancel_Click()
  710.     Me.Hide
  711. End Sub
  712. Private Sub lstHandlers_Click()
  713.     Dim sHandlerName$
  714.     sHandlerName = lstHandlers.List(lstHandlers.ListIndex)
  715.     If (sHandlerName = sDefaultHandler) Then
  716.         Template.HandlerName = "mWnd"
  717.     Else
  718.         Template.HandlerName = sHandlerName
  719.     End If
  720.     ' Update navigation buttons
  721.     EnableNavControls mnCurStep
  722.     ' Update wizard state description
  723.     lblWizardState = Template.DescriptionText
  724. End Sub
  725. Private Sub lstMessages_Click(Index As Integer)
  726.     If (Index = 0) Then
  727.         ' Single message or template
  728.         If optMessage.Value Then
  729.             Template.FirstMessage = lstMessages(0).ItemData(lstMessages(0).ListIndex)
  730.             Template.LastMessage = Template.FirstMessage
  731.         ElseIf optTemplate.Value Then
  732.             Template.TemplateFile = VBInstance.TemplatePath + "/SGWindow/" + lstMessages(0).List(lstMessages(0).ListIndex)
  733.         End If
  734.     ElseIf (Index = 1) Then
  735.         ' Message range
  736.         If (lstMessages(1).SelCount > 1) Then
  737.             Dim nSelStart%, nSelEnd%, nItems%, i%
  738.             
  739.             ' Find first and last selected item in the first selection block
  740.             nItems = lstMessages(1).ListCount
  741.             For i = 0 To nItems - 1
  742.                 If lstMessages(1).Selected(i) Then nSelStart = i: Exit For
  743.             Next
  744.             nSelEnd = -1
  745.             For i = i To nItems - 1
  746.                 If Not lstMessages(1).Selected(i) Then nSelEnd = i - 1: Exit For
  747.             Next
  748.             If (nSelEnd < 0) Then nSelEnd = nItems - 1
  749.             
  750.             ' Get message range
  751.             Template.FirstMessage = lstMessages(1).ItemData(nSelStart)
  752.             Template.LastMessage = lstMessages(1).ItemData(nSelEnd)
  753.         Else
  754.             Template.FirstMessage = wm_NULL
  755.             Template.LastMessage = wm_NULL
  756.         End If
  757.     End If
  758.     ' Update navigation buttons
  759.     EnableNavControls mnCurStep
  760.     ' Update wizard state description
  761.     lblWizardState = Template.DescriptionText
  762. End Sub
  763. Private Sub optMessage_Click()
  764.     Template.FirstMessage = wm_NULL
  765.     Template.LastMessage = wm_NULL
  766.     Template.TemplateFile = VBInstance.TemplatePath + "\SGWindow\DefSingleMsg.swt"
  767.     lstMessages(0).Enabled = True
  768.     lstMessages(1).Enabled = False
  769.     FillMessages lstMessages(0)
  770.     ' Update navigation buttons
  771.     EnableNavControls mnCurStep
  772.     ' Update description
  773.     lblWizardState = Template.DescriptionText
  774. End Sub
  775. Private Sub optRange_Click()
  776.     Template.FirstMessage = wm_NULL
  777.     Template.LastMessage = wm_NULL
  778.     Template.TemplateFile = VBInstance.TemplatePath + "/SGWindow/DefMsgRange.swt"
  779.     lstMessages(0).Enabled = False
  780.     lstMessages(1).Enabled = True
  781.     FillMessages lstMessages(1)
  782.     ' Update navigation buttons
  783.     EnableNavControls mnCurStep
  784.     ' Update description
  785.     lblWizardState = Template.DescriptionText
  786. End Sub
  787. Private Sub optTemplate_Click()
  788.     Template.FirstMessage = wm_NULL
  789.     Template.LastMessage = wm_NULL
  790.     Template.TemplateFile = ""
  791.     lstMessages(0).Enabled = True
  792.     lstMessages(1).Enabled = False
  793.     FillTemplates lstMessages(0)
  794.     ' Update navigation buttons
  795.     EnableNavControls mnCurStep
  796.     ' Update description
  797.     lblWizardState = Template.DescriptionText
  798. End Sub
  799. Private Sub tvwControls_Click()
  800.     On Error GoTo Error_
  801.     Dim tvNode As Node
  802.     Dim wndObj As Object
  803.     ' Update WizardTemplate object
  804.     Set tvNode = tvwControls.SelectedItem
  805.     If tvNode Is Nothing Then Exit Sub
  806.     Dim sType$
  807.     sType = Str_Token(tvNode.Tag, ";", 0)
  808.     Template.FormName = Str_Token(tvNode.Tag, ";", 1)
  809.     Template.ControlName = ""
  810.     If (sType = "Control") Then
  811.         Template.ControlName = Str_Token(tvNode.Tag, ";", 2)
  812.     End If
  813.     ' Update navigation buttons
  814.     EnableNavControls mnCurStep
  815.     ' Update description
  816.     lblWizardState = Template.DescriptionText
  817.     Exit Sub
  818. Error_:
  819.     MsgBox Error$
  820. End Sub
  821.