home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic 4 Unleashed
/
Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso
/
source
/
chap14
/
vbu1401.frm
< prev
next >
Wrap
Text File
|
1995-10-07
|
11KB
|
419 lines
VERSION 4.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4140
ClientLeft = 1245
ClientTop = 1950
ClientWidth = 5400
Height = 4830
Left = 1185
LinkTopic = "Form1"
ScaleHeight = 4140
ScaleWidth = 5400
Top = 1320
Width = 5520
Begin VB.TextBox Text2
Height = 315
Left = 1500
TabIndex = 5
Text = "Text2"
Top = 2220
Width = 1515
End
Begin VB.TextBox Text1
Height = 315
Left = 1500
TabIndex = 4
Text = "Text1"
Top = 1800
Width = 1515
End
Begin VB.CommandButton cmdColor
Caption = "&Control ForeColor"
Height = 495
Index = 3
Left = 3540
TabIndex = 3
Top = 2220
Width = 1755
End
Begin VB.CommandButton cmdColor
Caption = "&Control BackColor"
Height = 495
Index = 2
Left = 3540
TabIndex = 2
Top = 1620
Width = 1755
End
Begin VB.CommandButton cmdColor
Caption = "&Form ForeColor"
Height = 495
Index = 1
Left = 3540
TabIndex = 1
Top = 1020
Width = 1755
End
Begin VB.CommandButton cmdColor
Caption = "&Form BackColor"
Height = 495
Index = 0
Left = 3540
TabIndex = 0
Top = 420
Width = 1755
End
Begin VB.Label Label2
Caption = "Label2"
Height = 315
Left = 540
TabIndex = 7
Top = 2220
Width = 855
End
Begin VB.Label Label1
Caption = "Label1"
Height = 315
Left = 540
TabIndex = 6
Top = 1800
Width = 855
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 4440
Top = 2820
_Version = 65536
_ExtentX = 847
_ExtentY = 847
_StockProps = 0
End
Begin VB.Menu mnuFile
Caption = "&File"
Begin VB.Menu mnuFileExit
Caption = "E&xit"
End
End
Begin VB.Menu mnuPref
Caption = "&Preferences"
Begin VB.Menu mnuPrefDefaultColor
Caption = "&Default Colors"
End
Begin VB.Menu mnuPrefSysColor
Caption = "&System Colors"
End
Begin VB.Menu mnuPrefUserColor
Caption = "&User Colors"
Checked = -1 'True
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
'
' internal vars for INI values
'
Dim cDatabase As String
Dim cLocalPrinter As String
Dim cLocalModem As String
'
' form size/location
Dim nFormWidth As Integer
Dim nFormHeight As Integer
Dim nFormLeft As Integer
Dim nFormTop As Integer
'
' colors
'
Dim lUserColor(4) As Long
Const vbuFormBG = 1
Const vbuFormFG = 2
Const vbuControlBG = 3
Const vbuControlFG = 4
Dim gblColorSet As String
'
' confirmation
Dim gblConfirm As String
Private Sub cmdColor_Click(Index As Integer)
'
' handle user color settings
'
Dim nTemp As Integer
'
Select Case Index
Case 0
' form back color
CommonDialog1.DialogTitle = "Select Form Background Color"
CommonDialog1.ShowColor
lUserColor(Index + 1) = CommonDialog1.Color
Case 1
' form fore color
CommonDialog1.DialogTitle = "Select Form Foreground Color"
CommonDialog1.ShowColor
lUserColor(Index + 1) = CommonDialog1.Color
Case 2
' control back color
CommonDialog1.DialogTitle = "Select Control Background Color"
CommonDialog1.ShowColor
lUserColor(Index + 1) = CommonDialog1.Color
Case 3
' control fore color
CommonDialog1.DialogTitle = "Select Control Foreground Color"
CommonDialog1.ShowColor
lUserColor(Index + 1) = CommonDialog1.Color
End Select
'
' check for confirmation first
If gblConfirm = "YES" Then
nTemp = MsgBox("Update Current Color Scheme?", vbInformation + vbYesNo, "Color Configuration")
Else
nTemp = vbYes
End If
'
' if ok, then update colors
If nTemp = vbYes Then
SetUserColors ' set colors
End If
'
End Sub
Private Sub Form_Activate()
LoadINIVars ' read INI stuff
'
Select Case gblColorSet
Case "DEFAULT"
mnuPrefDefaultColor_Click
Case "SYSTEM"
mnuPrefSysColor_Click
Case "USER"
mnuPrefUserColor_Click
End Select
'
Me.Cls
Me.Print "gblIniFile="; gblIniFile
Me.Print "cDatabase="; cDatabase
Me.Print "cLocalPrinter="; cLocalPrinter
Me.Print "cLocalModem="; cLocalModem
'
' re-size based on INI settings
'
Me.Left = nFormLeft
Me.Width = nFormWidth
Me.Height = nFormHeight
Me.Top = nFormTop
'
End Sub
Public Sub LoadINIVars()
'
' read ini values into internal variables
'
' attempt to access settings
If OpenINI() = False Then
Unload Me ' oops!
End If
'
cDatabase = GetIniStr("System", "Database", "vbu1401.mdb")
cLocalPrinter = GetIniStr("System", "LocalPrinter", "No")
cLocalModem = GetIniStr("System", "LocalModem", "No")
'
' get form size and location info
'
nFormWidth = GetIniStr("Forms", Me.Name + ".Width", "6800")
nFormHeight = GetIniStr("Forms", Me.Name + ".Height", "4550")
nFormLeft = GetIniStr("Forms", Me.Name + ".Left", "1200")
nFormTop = GetIniStr("Forms", Me.Name + ".Top", "1300")
'
' get confirmation flag
gblConfirm = UCase(GetIniStr("system", "Confirm", "YES"))
'
' get color set
gblColorSet = UCase(GetIniStr("system", "ColorSet", "Default"))
'
End Sub
Public Sub NewData()
'
' create a new database
'
Dim dbFile As Database
Dim cDBFile As String
Dim cTable1 As String
Dim cTable2 As String
Dim nTemp As Integer
'
' set vars
cDBFile = "c:\source\chap14\ch1401.mdb"
cTable1 = "CREATE Table1 (CustID TEXT(10),CustName TEXT(30),CustType TEXT(10));"
cTable2 = "CREATE Table2 (CustType TEXT(10),TypeName TEXT(20));"
'
' kill any current database
nTemp = MsgBox("Ready to Delete Any Existing Database?", vbInformation + vbYesNo, "Create Database")
If nTemp = vbNo Then
MsgBox "Create Database Canceled"
Else
On Error Resume Next
Kill cDBFile
On Error GoTo 0
'
' create empty DB
Set dbFile = DBEngine.CreateDatabase(cDBFile)
'
' create tables
db.Execute cTable1
db.Execute cTable2
'
' add additional tables, indexes, relations, etc.
'
MsgBox "Database has been Created"
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
'
' store form size & location
'
Dim lTemp As Long
Dim cForm As String
'
cForm = Me.Name
'
lTemp = WriteINIStr("Forms", cForm + ".Top", Str(Me.Top))
lTemp = WriteINIStr("Forms", cForm + ".Left", Str(Me.Left))
lTemp = WriteINIStr("Forms", cForm + ".Width", Str(Me.Width))
lTemp = WriteINIStr("Forms", cForm + ".Height", Str(Me.Height))
'
If gblColorSet = "USER" Then
lTemp = WriteINIStr("forms", cForm + ".formBG", Str(lUserColor(vbuFormBG)))
lTemp = WriteINIStr("forms", cForm + ".formFG", Str(lUserColor(vbuFormFG)))
lTemp = WriteINIStr("forms", cForm + ".controlBG", Str(lUserColor(vbuControlBG)))
lTemp = WriteINIStr("forms", cForm + ".controlFG", Str(lUserColor(vbuControlFG)))
End If
'
lTemp = WriteINIStr("System", "ColorSet", gblColorSet)
End Sub
Public Sub LoadSysColors()
'
' load the colors from the current
' windows color scheme
'
Dim ctlTemp As Control
'
' set colors for all controls on form
On Error Resume Next
For Each ctlTemp In Me.Controls
ctlTemp.BackColor = vbWindowBackground
ctlTemp.ForeColor = vbWindowText
Next
On Error GoTo 0
'
' set colors for form itself
Me.BackColor = vbApplicationWorkspace
Me.ForeColor = vbWindowText
'
End Sub
Public Sub LoadUserColors()
'
' load colors from ini file
'
Dim cTemp As String
'
cTemp = GetIniStr("Forms", Me.Name + ".formBG", Str(Me.BackColor))
lUserColor(vbuFormBG) = Val(cTemp)
'
cTemp = GetIniStr("Forms", Me.Name + ".formFG", Str(Me.ForeColor))
lUserColor(vbuFormFG) = Val(cTemp)
'
cTemp = GetIniStr("Forms", Me.Name + ".controlBG", Str(Text1.BackColor))
lUserColor(vbuControlBG) = Val(cTemp)
'
cTemp = GetIniStr("Forms", Me.Name + ".controlFG", Str(Text1.ForeColor))
lUserColor(vbuControlFG) = Val(cTemp)
'
SetUserColors ' set objects to selected colors
End Sub
Public Sub SetUserColors()
'
' set the form and controls
' to the selected colors
'
Dim ctlTemp As Control
'
' first the form
Me.BackColor = lUserColor(vbuFormBG)
Me.ForeColor = lUserColor(vbuFormFG)
'
' now all controls
On Error Resume Next
For Each ctlTemp In Me.Controls
ctlTemp.BackColor = lUserColor(vbuControlBG)
ctlTemp.ForeColor = lUserColor(vbuControlFG)
Next
On Error GoTo 0
'
End Sub
Private Sub mnuFileExit_Click()
Unload Me
End Sub
Private Sub mnuPrefDefaultColor_Click()
'
mnuPrefUserColor.Checked = False
mnuPrefSysColor.Checked = False
mnuprefdefaultcolor.Checked = True
gblColorSet = "DEFAULT"
LoadDefaultColors
'
End Sub
Private Sub mnuPrefSysColor_Click()
'
mnuprefdefaultcolor.Checked = False
mnuPrefUserColor.Checked = False
mnuPrefSysColor.Checked = True
gblColorSet = "SYSTEM"
LoadSysColors
'
End Sub
Private Sub mnuPrefUserColor_Click()
'
mnuprefdefaultcolor.Checked = False
mnuPrefSysColor.Checked = False
mnuPrefUserColor.Checked = True
gblColorSet = "USER"
LoadUserColors
'
End Sub
Public Sub LoadDefaultColors()
'
' load the original color set
'
lUserColor(vbuFormBG) = &H8000000F
lUserColor(vbuFormFG) = &H80000012
lUserColor(vbuControlBG) = &H80000005
lUserColor(vbuControlFG) = &H80000008
'
SetUserColors
End Sub