home *** CD-ROM | disk | FTP | other *** search
Wrap
VERSION 5.00 Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "COMCTL32.OCX" Begin VB.Form frmWizard BorderStyle = 3 'Fixed Dialog Caption = "Stinga sgWindow Wizard" ClientHeight = 5484 ClientLeft = 2172 ClientTop = 1932 ClientWidth = 6912 LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 5484 ScaleWidth = 6912 ShowInTaskbar = 0 'False StartUpPosition = 2 'CenterScreen Begin VB.Frame fraStep BorderStyle = 0 'None Caption = "Select sgWindow Object Name" Enabled = 0 'False Height = 2016 Index = 3 Left = -10000 TabIndex = 19 Top = 972 Width = 4968 Begin VB.ListBox lstHandlers Height = 1776 Left = 0 TabIndex = 20 Top = 0 Width = 2928 End End Begin VB.Frame fraStep BorderStyle = 0 'None Caption = "Finish" Enabled = 0 'False Height = 1448 Index = 4 Left = -10000 TabIndex = 18 Top = 1920 Width = 4896 Begin VB.Label Label1 Caption = "To find wizard generated code search code module for text 'SGWindow Wizard'" BeginProperty Font Name = "Arial" Size = 10.2 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 792 Left = 0 TabIndex = 22 Top = 0 Width = 4788 WordWrap = -1 'True End End Begin VB.Frame fraStep BorderStyle = 0 'None Caption = "Select Message(s)" Enabled = 0 'False Height = 2448 Index = 2 Left = -10000 TabIndex = 9 Top = 1080 Width = 5112 Begin VB.ListBox lstMessages Height = 2160 Index = 1 Left = 1836 MultiSelect = 2 'Extended TabIndex = 16 Top = 36 Width = 3252 End Begin VB.ListBox lstMessages Height = 2160 Index = 0 Left = 1836 TabIndex = 15 Top = 36 Width = 3252 End Begin VB.OptionButton optTemplate Caption = "Predefined template" Height = 264 Left = 0 TabIndex = 14 Top = 1008 Width = 1884 End Begin VB.OptionButton optRange Caption = "Message &range" Height = 264 Left = 0 TabIndex = 13 Top = 522 Width = 1812 End Begin VB.OptionButton optMessage Caption = "Single &message" Height = 264 Left = 0 TabIndex = 12 Top = 36 Width = 1812 End Begin VB.Label lblMsgDescription Height = 192 Left = 108 TabIndex = 17 Top = 2232 Width = 4764 End End Begin VB.Frame fraStep BorderStyle = 0 'None Caption = "Welcome" Enabled = 0 'False Height = 1416 Index = 0 Left = 1560 TabIndex = 7 Top = 1680 Width = 4968 End Begin VB.Frame fraStep BorderStyle = 0 'None Caption = "Select Window" Enabled = 0 'False Height = 2628 Index = 1 Left = -10000 TabIndex = 8 Top = 900 Width = 5112 Begin ComctlLib.TreeView tvwControls Height = 2568 Left = 0 TabIndex = 10 Top = 0 Width = 5088 _ExtentX = 8975 _ExtentY = 4530 _Version = 327682 HideSelection = 0 'False Indentation = 423 LabelEdit = 1 LineStyle = 1 Style = 7 Appearance = 1 End End Begin VB.Frame frmSeparator Height = 72 Left = 108 TabIndex = 6 Top = 4716 Width = 6672 End Begin VB.CommandButton cmdBack Caption = "< &Back" Height = 372 Left = 3420 TabIndex = 2 Top = 4968 Width = 1068 End Begin VB.CommandButton cmdCancel Caption = "&Cancel" Height = 372 Left = 5688 TabIndex = 4 Top = 4968 Width = 1068 End Begin VB.CommandButton cmdNext Caption = "&Next >" Height = 372 Left = 4500 TabIndex = 3 Top = 4968 Width = 1068 End Begin VB.Image Image1 BorderStyle = 1 'Fixed Single Enabled = 0 'False Height = 4428 Left = 144 Picture = "frmSelectWindow.frx":0000 Stretch = -1 'True Top = 180 Width = 1284 End Begin ComctlLib.ImageList ImageList1 Left = 5400 Top = 4932 _ExtentX = 804 _ExtentY = 804 BackColor = -2147483643 ImageWidth = 16 ImageHeight = 15 MaskColor = 12632256 _Version = 327682 BeginProperty Images {0713E8C2-850A-101B-AFC0-4210102A8DA7} NumListImages = 2 BeginProperty ListImage1 {0713E8C3-850A-101B-AFC0-4210102A8DA7} Picture = "frmSelectWindow.frx":364C Key = "" EndProperty BeginProperty ListImage2 {0713E8C3-850A-101B-AFC0-4210102A8DA7} Picture = "frmSelectWindow.frx":3756 Key = "" EndProperty EndProperty End Begin VB.Label lblMessage Caption = "Message text" BeginProperty Font Name = "Arial" Size = 10.2 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 480 Left = 144 TabIndex = 11 Top = 4932 Width = 3000 End Begin VB.Label lblDescription Caption = "Page description" BeginProperty Font Name = "Arial" Size = 9 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 1128 Left = 1600 TabIndex = 1 Top = 612 Width = 5052 End Begin VB.Label lblWizardState BackColor = &H80000005& Caption = "description" BeginProperty Font Name = "Arial" Size = 9 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 876 Left = 1668 TabIndex = 5 Top = 3672 Width = 5016 End Begin VB.Label lblTitle Caption = "Page Title" BeginProperty Font Name = "Arial" Size = 18 Charset = 0 Weight = 700 Underline = 0 'False Italic = -1 'True Strikethrough = 0 'False EndProperty Height = 408 Left = 1600 TabIndex = 0 Top = 144 Width = 4836 End Begin VB.Label lblWizardState2 BackColor = &H80000005& BorderStyle = 1 'Fixed Single BeginProperty Font Name = "Arial" Size = 9 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 948 Left = 1596 TabIndex = 21 Top = 3636 Width = 5124 End Attribute VB_Name = "frmWizard" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False '-------------------------------------------------------------------------- ' File: FRMSELECTWINDOW.FRM ' This file is part of the 'Stinga sgWindow Wizard' project. ' Copyright (C) 1998 Stinga ' All rights reserved. '-------------------------------------------------------------------------- Option Explicit Public VBInstance As VBIDE.VBE Public Connect As Connect Const NUM_STEPS = 5 Const HELP_BASE = 1000 Const HELP_FILE = "" Const BTN_HELP = 0 Const BTN_CANCEL = 1 Const BTN_BACK = 2 Const BTN_NEXT = 3 Const BTN_FINISH = 4 Const STEP_INTRO = 0 Const STEP_1 = 1 Const STEP_2 = 2 Const STEP_3 = 3 Const STEP_FINISH = 4 Const DIR_NONE = 0 Const DIR_BACK = 1 Const DIR_NEXT = 2 Const FRM_TITLE = "Stinga sgWindow Wizard" Const sDefaultHandler = "Default handler (mWnd)" Public mnCurStep As Integer Dim mbFinishOK As Boolean ' Description strings Dim sTitles() As String Dim sDescriptions() As String ' Wizard template class Public Template As sgWindowTemplate Public Sub Clear() Template.Clear lstMessages(0).Clear lstMessages(1).Clear optMessage.Value = False optRange.Value = False optTemplate.Value = False End Sub '----------------------------------------------------------------------- ' Helper functions '----------------------------------------------------------------------- Private Sub FillMessages(lst As ListBox) On Error GoTo Error_ lst.Clear lst.ZOrder 0 Dim mi As MemberInfo For Each mi In Template.TypeLib.TypeInfos.NamedItem("WinMsg").Members lst.AddItem UCase(mi.name) lst.ItemData(lst.NewIndex) = mi.Value Next Exit Sub Error_: MsgBox Error$ End Sub Private Sub FillTemplates(lst As ListBox) lst.Clear lst.ZOrder 0 Dim sFileName As String sFileName = Dir(VBInstance.TemplatePath + "/SGWindow/*.swt") Do Until Len(sFileName) = 0 lst.AddItem sFileName sFileName = Dir Loop End Sub Private Sub FillHandlers(lst As ListBox) lst.Clear ' Add default window handler lst.AddItem sDefaultHandler If (Template.HandlerName = "mWnd") Then lst.Selected(0) = True End If ' Parse code module and extract all sgWindow objects If (Template.FormName <> "") Then Dim proj As VBProject Dim formCode As CodeModule Set proj = VBInstance.VBProjects.StartProject Set formCode = proj.VBComponents(Template.FormName).CodeModule Dim m As Member For Each m In formCode.Members If m.Type = vbext_mt_Variable Then Dim sLine$ sLine = formCode.Lines(m.CodeLocation, 1) If (InStr(sLine, "WithEvents") > 0) And (InStr(sLine, "Window") > 0) Then lst.AddItem m.name If (m.name = Template.HandlerName) Then lst.Selected(lst.NewIndex) = True End If End If End If Next End If End Sub Private Sub FillControlsTree(tv As TreeView) Dim el As Object Dim nodForm As Node tv.Nodes.Clear tv.ImageList = ImageList1 Dim proj As VBProject If VBInstance.VBProjects.Count > 0 Then Set proj = VBInstance.VBProjects.StartProject For Each el In proj.VBComponents If el.Type = vbext_ct_VBForm Then Set nodForm = tv.Nodes.Add(, , , el.name, 1) nodForm.Tag = "Form;" & el.name If (Template.FormName = el.name) Then nodForm.Selected = True nodForm.EnsureVisible End If AddControls tv, nodForm, el.name End If Next End If End Sub Private Sub AddControls(tv As TreeView, nodForm As Node, sFormName$) Dim ctl As VBControl Dim nodControl As Node Dim StartProj As VBProject Set StartProj = VBInstance.VBProjects.StartProject Dim Form As VBForm Set Form = StartProj.VBComponents(sFormName).Designer For Each ctl In Form.ContainedVBControls ' Get current control Dim ctlObj As Object Set ctlObj = ctl.ControlObject ' We are using controls with HWND On Error Resume Next Dim hwnd As Long hwnd = ctlObj.hwnd If Err = 0 Then Set nodControl = tv.Nodes.Add(nodForm, tvwChild, , ctlObj.name & " (" & ctl.ClassName & ")", 2) nodControl.Tag = "Control;" & sFormName & ";" & ctlObj.name If (Template.ControlName = ctlObj.name) Then nodControl.Selected = True nodControl.EnsureVisible End If End If Next End Sub Public Sub SetStep(nStep As Integer, nDirection As Integer) If nStep > mnCurStep Then If Not OnNextPage(mnCurStep, nStep) Then Exit Sub Else If Not OnBackPage(mnCurStep, nStep) Then Exit Sub End If Select Case nStep Case STEP_INTRO fraStep(nStep).Top = 1800 Case STEP_1 fraStep(nStep).Top = 950 Case STEP_2 fraStep(nStep).Top = 1300 Case STEP_3 fraStep(nStep).Top = 1000 Case STEP_FINISH fraStep(nStep).Top = 1700 mbFinishOK = True Case Else ' Invalid page Exit Sub End Select ' Move to new step fraStep(mnCurStep).Enabled = False fraStep(nStep).Left = 1600 Dim h% h = lblWizardState.Top - fraStep(nStep).Top - 60 If (h < 0) Then h = 100 fraStep(nStep).Height = h lblDescription.ZOrder 0 If nStep <> mnCurStep Then fraStep(mnCurStep).Top = -10000 fraStep(mnCurStep).Left = -10000 End If fraStep(nStep).Enabled = True SetTitles nStep SetNavBtns nStep mnCurStep = nStep OnPageOpen mnCurStep EnableNavControls mnCurStep ' Update description lblWizardState = Template.DescriptionText End Sub Private Sub SetTitles(nStep As Integer) On Error Resume Next Me.Caption = sTitles(nStep) & " - " & FRM_TITLE lblTitle = sTitles(nStep) lblDescription = sDescriptions(nStep) End Sub Private Sub SetNavBtns(nStep As Integer) mnCurStep = nStep If mnCurStep = 0 Then cmdNext.Caption = "&Next >" cmdBack.Enabled = False cmdNext.Enabled = True ElseIf mnCurStep = NUM_STEPS - 1 Then cmdNext.Caption = "&Finish" cmdNext.Enabled = False cmdBack.Enabled = True Else cmdNext.Caption = "&Next >" cmdBack.Enabled = True cmdNext.Enabled = True End If If mbFinishOK Then cmdNext.Enabled = True Else cmdNext.Enabled = True End If End Sub Private Function OnPageOpen(nPage%) As Boolean OnPageOpen = True lblWizardState.Visible = True lblWizardState2.Visible = True Select Case nPage Case STEP_INTRO lblWizardState.Visible = False lblWizardState2.Visible = False Case STEP_1 Me.MousePointer = vbHourglass lblMessage.Caption = "Parsing start up project..." FillControlsTree tvwControls lblMessage.Caption = "" Me.MousePointer = vbArrow Case STEP_2 Case STEP_3 FillHandlers lstHandlers Case STEP_FINISH Case Else ' Invalid page End Select End Function Private Function OnBackPage(nCurrPage%, nNewPage%) As Boolean OnBackPage = True Select Case nCurrPage Case STEP_INTRO Case STEP_1 Case STEP_2 Case STEP_3 Case STEP_FINISH Case Else ' Invalid page End Select End Function Private Function OnNextPage(nCurrPage%, nNewPage%) As Boolean OnNextPage = True Select Case nCurrPage Case STEP_INTRO Case STEP_1 ' Can not go to the next page if no window is selected If (Template.FormName = "") And (Template.ControlName = "") Then OnNextPage = False End If Case STEP_2 ' Can not go to the next page if tehere is ' no message or template file selected If optMessage.Value Or optRange.Value Then If (Template.FirstMessage = wm_NULL) Then OnNextPage = False ElseIf optTemplate.Value Then If Template.TemplateFile = "" Then OnNextPage = False End If Case STEP_3 ' Can not go to the next page if no handler is selected If (Template.HandlerName = "") Then OnNextPage = False End If Case STEP_FINISH Case Else ' Invalid page End Select End Function Private Sub EnableNavControls(nPage%) cmdBack.Enabled = True cmdNext.Enabled = True Select Case nPage Case STEP_INTRO cmdBack.Enabled = False Case STEP_1 If (Template.FormName = "") And (Template.ControlName = "") Then cmdNext.Enabled = False End If Case STEP_2 If optMessage.Value Or optRange.Value Then If (Template.FirstMessage = wm_NULL) Then cmdNext.Enabled = False End If ElseIf optTemplate.Value Then If Template.TemplateFile = "" Then cmdNext.Enabled = False End If End If Case STEP_3 If (Template.HandlerName = "") Then cmdNext.Enabled = False End If Case STEP_FINISH Case Else ' Invalid page End Select End Sub '----------------------------------------------------------------------- ' Form event handlers '----------------------------------------------------------------------- Private Sub Form_Load() On Error GoTo Error_ Set Template = New sgWindowTemplate mbFinishOK = False Dim i% For i = 0 To NUM_STEPS - 1 fraStep(i).Left = -10000 Next ' Initialize titles and descriptions ReDim sTitles(NUM_STEPS) As String ReDim sDescriptions(NUM_STEPS) As String sTitles(0) = "Welcome!" sDescriptions(0) = "Welcome to the sgWindow Wizard!" + vbCrLf + vbCrLf + _ "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." sTitles(1) = "Select Window Handle" sDescriptions(1) = "Select form or control you want to subclass." sTitles(2) = "Select Message(s)" sDescriptions(2) = "Select message or message range you want to handle." + vbCrLf + _ "If you select message handler template, wizard will insert predefined template into your code." sTitles(3) = "Select Handler Name" sDescriptions(3) = "Select message handler variable." sTitles(4) = "Finish!" sDescriptions(4) = "Press finish and sgWindow wizard will insert message handler into your application." SetStep 0, DIR_NONE lblMessage.Caption = "" Exit Sub Error_: MsgBox Error$ End Sub Private Sub cmdBack_Click() SetStep mnCurStep - 1, DIR_NONE End Sub Private Sub cmdNext_Click() On Error GoTo Error_ If mnCurStep = (NUM_STEPS - 1) Then ' Finish If (Template.FormName <> "") Then Dim code As CodeModule Set code = VBInstance.VBProjects.StartProject.VBComponents(Template.FormName).CodeModule ' Make sure that SGWindow is referenced in the active project ' On Error Resume Next ' If Not IsSGWindowReferenced Then ' MsgBox "SG Window is not referenced!" & vbCrLf & _ ' "Open Project menu and click on the References... command to add SG Window to the list of the referenced components" ' Exit Sub ' End If On Error GoTo Error_ If Not Template.UpdateCodeModule(code, Template.FormName) Then MsgBox "Code insertion failed!", vbOKOnly, "SG Window Wizard" End If End If Me.Hide Else ' Next page SetStep mnCurStep + 1, DIR_NONE End If Exit Sub Error_: MsgBox Error$ End Sub Private Sub cmdCancel_Click() Me.Hide End Sub Private Sub lstHandlers_Click() Dim sHandlerName$ sHandlerName = lstHandlers.List(lstHandlers.ListIndex) If (sHandlerName = sDefaultHandler) Then Template.HandlerName = "mWnd" Else Template.HandlerName = sHandlerName End If ' Update navigation buttons EnableNavControls mnCurStep ' Update wizard state description lblWizardState = Template.DescriptionText End Sub Private Sub lstMessages_Click(Index As Integer) If (Index = 0) Then ' Single message or template If optMessage.Value Then Template.FirstMessage = lstMessages(0).ItemData(lstMessages(0).ListIndex) Template.LastMessage = Template.FirstMessage ElseIf optTemplate.Value Then Template.TemplateFile = VBInstance.TemplatePath + "/SGWindow/" + lstMessages(0).List(lstMessages(0).ListIndex) End If ElseIf (Index = 1) Then ' Message range If (lstMessages(1).SelCount > 1) Then Dim nSelStart%, nSelEnd%, nItems%, i% ' Find first and last selected item in the first selection block nItems = lstMessages(1).ListCount For i = 0 To nItems - 1 If lstMessages(1).Selected(i) Then nSelStart = i: Exit For Next nSelEnd = -1 For i = i To nItems - 1 If Not lstMessages(1).Selected(i) Then nSelEnd = i - 1: Exit For Next If (nSelEnd < 0) Then nSelEnd = nItems - 1 ' Get message range Template.FirstMessage = lstMessages(1).ItemData(nSelStart) Template.LastMessage = lstMessages(1).ItemData(nSelEnd) Else Template.FirstMessage = wm_NULL Template.LastMessage = wm_NULL End If End If ' Update navigation buttons EnableNavControls mnCurStep ' Update wizard state description lblWizardState = Template.DescriptionText End Sub Private Sub optMessage_Click() Template.FirstMessage = wm_NULL Template.LastMessage = wm_NULL Template.TemplateFile = VBInstance.TemplatePath + "\SGWindow\DefSingleMsg.swt" lstMessages(0).Enabled = True lstMessages(1).Enabled = False FillMessages lstMessages(0) ' Update navigation buttons EnableNavControls mnCurStep ' Update description lblWizardState = Template.DescriptionText End Sub Private Sub optRange_Click() Template.FirstMessage = wm_NULL Template.LastMessage = wm_NULL Template.TemplateFile = VBInstance.TemplatePath + "/SGWindow/DefMsgRange.swt" lstMessages(0).Enabled = False lstMessages(1).Enabled = True FillMessages lstMessages(1) ' Update navigation buttons EnableNavControls mnCurStep ' Update description lblWizardState = Template.DescriptionText End Sub Private Sub optTemplate_Click() Template.FirstMessage = wm_NULL Template.LastMessage = wm_NULL Template.TemplateFile = "" lstMessages(0).Enabled = True lstMessages(1).Enabled = False FillTemplates lstMessages(0) ' Update navigation buttons EnableNavControls mnCurStep ' Update description lblWizardState = Template.DescriptionText End Sub Private Sub tvwControls_Click() On Error GoTo Error_ Dim tvNode As Node Dim wndObj As Object ' Update WizardTemplate object Set tvNode = tvwControls.SelectedItem If tvNode Is Nothing Then Exit Sub Dim sType$ sType = Str_Token(tvNode.Tag, ";", 0) Template.FormName = Str_Token(tvNode.Tag, ";", 1) Template.ControlName = "" If (sType = "Control") Then Template.ControlName = Str_Token(tvNode.Tag, ";", 2) End If ' Update navigation buttons EnableNavControls mnCurStep ' Update description lblWizardState = Template.DescriptionText Exit Sub Error_: MsgBox Error$ End Sub