⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmain.frm

📁 《VB6数据库开发指南》所有的例程的源码
💻 FRM
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "COMCTL32.OCX"
Begin VB.Form frmMain 
   Caption         =   "Database Explorer"
   ClientHeight    =   6060
   ClientLeft      =   1605
   ClientTop       =   2550
   ClientWidth     =   5835
   LinkTopic       =   "Form1"
   ScaleHeight     =   6060
   ScaleWidth      =   5835
   Begin ComctlLib.Toolbar tbToolBar 
      Align           =   1  'Align Top
      Height          =   420
      Left            =   0
      TabIndex        =   1
      Top             =   0
      Width           =   5835
      _ExtentX        =   10292
      _ExtentY        =   741
      ButtonWidth     =   635
      ButtonHeight    =   582
      Appearance      =   1
      ImageList       =   "imlIcons"
      _Version        =   327680
   End
   Begin ComctlLib.TreeView tvTreeView 
      Height          =   4800
      Left            =   0
      TabIndex        =   6
      Top             =   705
      Width           =   2016
      _ExtentX        =   3545
      _ExtentY        =   8467
      _Version        =   327680
      Indentation     =   176
      LabelEdit       =   1
      LineStyle       =   1
      Sorted          =   -1  'True
      Style           =   6
      Appearance      =   1
   End
   Begin VB.PictureBox picSplitter 
      BackColor       =   &H00808080&
      BorderStyle     =   0  'None
      FillColor       =   &H00808080&
      Height          =   4800
      Left            =   5400
      ScaleHeight     =   2090.126
      ScaleMode       =   0  'User
      ScaleWidth      =   780
      TabIndex        =   7
      Top             =   705
      Visible         =   0   'False
      Width           =   72
   End
   Begin ComctlLib.ListView lvListView 
      Height          =   4800
      Left            =   2070
      TabIndex        =   5
      Top             =   720
      Width           =   3210
      _ExtentX        =   5662
      _ExtentY        =   8467
      View            =   3
      Sorted          =   -1  'True
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      _Version        =   327680
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   0
   End
   Begin VB.PictureBox picTitles 
      Align           =   1  'Align Top
      Appearance      =   0  'Flat
      BorderStyle     =   0  'None
      ForeColor       =   &H80000008&
      Height          =   300
      Left            =   0
      ScaleHeight     =   300
      ScaleWidth      =   5835
      TabIndex        =   2
      TabStop         =   0   'False
      Top             =   420
      Width           =   5835
      Begin VB.Label lblTitle 
         BorderStyle     =   1  'Fixed Single
         Caption         =   "Properties"
         Height          =   270
         Index           =   1
         Left            =   2078
         TabIndex        =   4
         Tag             =   " ListView:"
         Top             =   12
         Width           =   3216
      End
      Begin VB.Label lblTitle 
         BorderStyle     =   1  'Fixed Single
         Caption         =   "Database"
         Height          =   270
         Index           =   0
         Left            =   0
         TabIndex        =   3
         Tag             =   " TreeView:"
         Top             =   12
         Width           =   2016
      End
   End
   Begin ComctlLib.StatusBar sbStatusBar 
      Align           =   2  'Align Bottom
      Height          =   270
      Left            =   0
      TabIndex        =   0
      Top             =   5790
      Width           =   5835
      _ExtentX        =   10292
      _ExtentY        =   476
      SimpleText      =   ""
      _Version        =   327680
      BeginProperty Panels {0713E89E-850A-101B-AFC0-4210102A8DA7} 
         NumPanels       =   3
         BeginProperty Panel1 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
            AutoSize        =   1
            Object.Width           =   4657
            Text            =   "Status"
            TextSave        =   "Status"
            Object.Tag             =   ""
         EndProperty
         BeginProperty Panel2 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
            Style           =   6
            AutoSize        =   2
            TextSave        =   "6/15/97"
            Object.Tag             =   ""
         EndProperty
         BeginProperty Panel3 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
            Style           =   5
            AutoSize        =   2
            TextSave        =   "7:09 PM"
            Object.Tag             =   ""
         EndProperty
      EndProperty
   End
   Begin MSComDlg.CommonDialog dlgCommonDialog 
      Left            =   2700
      Top             =   2700
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   327680
   End
   Begin VB.Image imgSplitter 
      Height          =   4788
      Left            =   1965
      MousePointer    =   9  'Size W E
      Top             =   705
      Width           =   150
   End
   Begin ComctlLib.ImageList imlIcons 
      Left            =   2700
      Top             =   1440
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   16
      ImageHeight     =   16
      MaskColor       =   12632256
      _Version        =   327680
      BeginProperty Images {0713E8C2-850A-101B-AFC0-4210102A8DA7} 
         NumListImages   =   11
         BeginProperty ListImage1 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":0000
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":01A2
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":0344
            Key             =   ""
         EndProperty
         BeginProperty ListImage4 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":04E6
            Key             =   ""
         EndProperty
         BeginProperty ListImage5 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":0688
            Key             =   ""
         EndProperty
         BeginProperty ListImage6 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":082A
            Key             =   ""
         EndProperty
         BeginProperty ListImage7 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":09CC
            Key             =   ""
         EndProperty
         BeginProperty ListImage8 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":0B6E
            Key             =   ""
         EndProperty
         BeginProperty ListImage9 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":0D10
            Key             =   ""
         EndProperty
         BeginProperty ListImage10 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":0EB2
            Key             =   ""
         EndProperty
         BeginProperty ListImage11 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":1054
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin VB.Menu mnuFile 
      Caption         =   "&File"
      Begin VB.Menu mnuFileOpen 
         Caption         =   "&Open"
      End
      Begin VB.Menu mnuFileNew 
         Caption         =   "&New"
      End
      Begin VB.Menu mnuFileBar1 
         Caption         =   "-"
      End
      Begin VB.Menu mnuFileClose 
         Caption         =   "&Close"
      End
   End
   Begin VB.Menu mnuTable 
      Caption         =   "&Table"
      Begin VB.Menu mnuTableAdd 
         Caption         =   "&Add"
      End
      Begin VB.Menu mnuTableDelete 
         Caption         =   "&Delete"
      End
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

' used to manage the splitter
Dim mbMoving As Boolean
Const sglSplitLimit = 500

' the CDBExplorer class object
Private mcdbExp As CDBExplorer

Private Sub SelectRootNode()
On Error Resume Next

  ' Nodes collection is 1 based
  ' error is ignored if there are no nodes
  Set tvTreeView.SelectedItem = tvTreeView.Nodes(1)

End Sub
Private Sub Form_Load()
On Error Resume Next

  Me.Left = _
    GetSetting(App.Title, "Settings", "MainLeft", 1000)
  Me.Top = _
    GetSetting(App.Title, "Settings", "MainTop", 1000)
  Me.Width = _
    GetSetting(App.Title, "Settings", "MainWidth", 6500)
  Me.Height = _
    GetSetting(App.Title, "Settings", "MainHeight", 6500)

End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next

  Dim i As Integer
  
  'close all sub forms
  For i = Forms.Count - 1 To 1 Step -1
    Unload Forms(i)
  Next
  If Me.WindowState <> vbMinimized Then
    SaveSetting _
      App.Title, "Settings", "MainLeft", Me.Left
    SaveSetting _
      App.Title, "Settings", "MainTop", Me.Top
    SaveSetting _
      App.Title, "Settings", "MainWidth", Me.Width
    SaveSetting _
      App.Title, "Settings", "MainHeight", Me.Height
  End If

End Sub

Private Sub Form_Resize()
On Error Resume Next

  If Me.Width < 3000 Then Me.Width = 3000
  SizeControls imgSplitter.Left

End Sub

Private Sub imgSplitter_MouseDown( _
  Button As Integer, _
  Shift As Integer, _
  X As Single, _
  Y As Single)
On Error Resume Next
    
  With imgSplitter
    picSplitter.Move .Left, .Top, .Width \ 2, .Height - 20
  End With
  picSplitter.Visible = True
  mbMoving = True
    
End Sub

Private Sub imgSplitter_MouseMove( _
  Button As Integer, _
  Shift As Integer, _
  X As Single, _
  Y As Single)
    
  Dim sglPos As Single
  
  If mbMoving Then
    sglPos = X + imgSplitter.Left
    If sglPos < sglSplitLimit Then
      picSplitter.Left = sglSplitLimit
    ElseIf sglPos > Me.Width - sglSplitLimit Then
      picSplitter.Left = Me.Width - sglSplitLimit
    Else
      picSplitter.Left = sglPos
    End If
  End If
    
End Sub

Private Sub imgSplitter_MouseUp( _
  Button As Integer, _
  Shift As Integer, _
  X As Single, _
  Y As Single)
    
  SizeControls picSplitter.Left
  picSplitter.Visible = False
  mbMoving = False

End Sub

Private Sub SizeControls(X As Single)
On Error Resume Next
    
  'set the width
  If X < 1500 Then X = 1500
  If X > (Me.Width - 1500) Then X = Me.Width - 1500
  tvTreeView.Width = X
  imgSplitter.Left = X
  lvListView.Left = X + 40
  lvListView.Width = Me.Width - (tvTreeView.Width + 140)
  lblTitle(0).Width = tvTreeView.Width
  lblTitle(1).Left = lvListView.Left + 20
  lblTitle(1).Width = lvListView.Width - 40
  
  'set the top
  If tbToolBar.Visible Then
    tvTreeView.Top = tbToolBar.Height + picTitles.Height
  Else
    tvTreeView.Top = picTitles.Height
  End If
  lvListView.Top = tvTreeView.Top
  
  'set the height
  If sbStatusBar.Visible Then
    tvTreeView.Height = _
      Me.ScaleHeight - _
      (picTitles.Top + picTitles.Height + sbStatusBar.Height)
  Else
    tvTreeView.Height = _
      Me.ScaleHeight - _
      (picTitles.Top + picTitles.Height)
  End If
  
  lvListView.Height = tvTreeView.Height
  imgSplitter.Top = tvTreeView.Top
  imgSplitter.Height = tvTreeView.Height

End Sub

Private Sub tvTreeView_Expand(ByVal Node As ComctlLib.Node)
' Expand the node
On Error GoTo ProcError

  Screen.MousePointer = vbHourglass

  ' the class does the work
  mcdbExp.ExpandNode Node
  
ProcExit:
  Screen.MousePointer = vbDefault
  Exit Sub
  
ProcError:
  MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
  Resume ProcExit

End Sub

Private Sub tvTreeView_NodeClick(ByVal Node As ComctlLib.Node)
' Display the properties of the selected node in the listview
On Error GoTo ProcError

  Screen.MousePointer = vbHourglass

  ' the class does the work
  mcdbExp.ListProperties Node

ProcExit:
  Screen.MousePointer = vbDefault
  Exit Sub

ProcError:
  MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
  Resume ProcExit

End Sub

Private Sub mnuFileOpen_Click()
' open a database
On Error GoTo ProcError

  Dim strDBName As String
  
  Screen.MousePointer = vbHourglass

  strDBName = GetOpenDBName(dlgCommonDialog)
  If Len(strDBName) Then
    Set mcdbExp = Nothing
    Set mcdbExp = New CDBExplorer
    mcdbExp.ExploreDatabase strDBName, tvTreeView, lvListView
  End If
  
  ' no node is selected by default, so we
  ' select the root node here
  SelectRootNode

ProcExit:
  Screen.MousePointer = vbDefault
  Exit Sub

ProcError:
  MsgBox Err.Description
  Resume ProcExit

End Sub

Private Sub mnuFileNew_Click()
' create a new database
On Error GoTo ProcError

  Dim strDBName As String

  Screen.MousePointer = vbHourglass

  ' get the file name
  strDBName = GetNewDBName(dlgCommonDialog)
  ' kill it if it exists
  ' note that GetDBName prompts to confirm overwrite
  On Error Resume Next
  Kill strDBName
  ' create the database
  CreateDB strDBName

  ' explore it
  Set mcdbExp = New CDBExplorer
  mcdbExp.ExploreDatabase strDBName, tvTreeView, lvListView

  SelectRootNode

ProcExit:
  Screen.MousePointer = vbDefault
  Exit Sub

ProcError:
  MsgBox Err.Description
  Resume ProcExit

End Sub

Private Sub mnuFileClose_Click()
  'unload the form
  Unload Me
End Sub

Private Sub mnuTable_Click()
' enable/disable controls
On Error GoTo ProcError

  If mcdbExp Is Nothing Then
    ' no database open
    mnuTableAdd.Enabled = False
    mnuTableDelete.Enabled = False
  Else
    ' enable add
    mnuTableAdd.Enabled = True
    ' only enable delete if a tabledef is selected
    If mcdbExp.NodeType(tvTreeView.SelectedItem) = _
      "TableDef" Then
      mnuTableDelete.Enabled = True
    Else
      mnuTableDelete.Enabled = False
    End If
  End If

ProcExit:
  Exit Sub

ProcError:
  MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
  Resume ProcExit

End Sub
Private Sub mnuTableAdd_Click()
On Error GoTo ProcError

  mcdbExp.AddTable

ProcExit:
  Exit Sub

ProcError:
  MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
  Resume ProcExit

End Sub

Private Sub mnuTableDelete_Click()
On Error GoTo ProcError

  mcdbExp.DeleteTable tvTreeView.SelectedItem.Text

ProcExit:
  Exit Sub
  
ProcError:
  MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
  Resume ProcExit

End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -