home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Planet Source Code Jumbo …e CD Visual Basic 1 to 7
/
5_2007-2008.ISO
/
data
/
Zips
/
vbPainter-2107903302008.psc
/
Class
/
ColorDlg.cls
< prev
next >
Wrap
Text File
|
2006-01-15
|
5KB
|
193 lines
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CFDialog"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' CFDialog ColorDlg.cls Color Dialog
' From vbAccelerator.com
Option Explicit
' EG Color
'Dim CF As CFDialog
'Dim TheColor As Long
' Set CF = New CFDialog
' If CF.VBChooseColor(TheColor, , , , Me.hwnd) Then
' DrawColor = TheColor
' Set CF = Nothing
'Public Enum EErrorCommonDialog
' eeBaseCommonDialog = 13450 ' CommonDialog
'End Enum
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long
'Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
' lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Private Declare Sub CopyMemoryStr Lib "kernel32" Alias "RtlMoveMemory" ( _
lpvDest As Any, ByVal lpvSource As String, ByVal cbCopy As Long)
Private Type TCHOOSECOLOR
lStructSize As Long
hWndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As Long
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As Long
End Type
Private Declare Function ChooseColor Lib "comdlg32.dll" Alias _
"ChooseColorA" (pChoosecolor As TCHOOSECOLOR) As Long
Public Enum EChooseColor
CC_RGBInit = &H1
CC_FullOpen = &H2
CC_PreventFullOpen = &H4
CC_ColorShowHelp = &H8
' Win95 only
CC_SolidColor = &H80
CC_AnyColor = &H100
' End Win95 only
CC_ENABLEHOOK = &H10
CC_ENABLETEMPLATE = &H20
CC_EnableTemplateHandle = &H40
End Enum
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function CommDlgExtendedError Lib "COMDLG32" () As Long
' Array of custom colors lasts for life of app
Private alCustom(0 To 15) As Long, fNotFirst As Boolean
Private m_lApiReturn As Long
Private m_lExtendedError As Long
'Public Property Get APIReturn() As Long
' 'return object's APIReturn property
' APIReturn = m_lApiReturn
'End Property
'Public Property Get ExtendedError() As Long
' 'return object's ExtendedError property
' ExtendedError = m_lExtendedError
'End Property
'#If fComponent Then
Private Sub Class_Initialize()
InitColors
End Sub
'#End If
'' ChooseColor wrapper
Function VBChooseColor(Color As Long, _
Optional AnyColor As Boolean = True, _
Optional FullOpen As Boolean = False, _
Optional DisableFullOpen As Boolean = False, _
Optional owner As Long = -1, _
Optional flags As Long) As Boolean
Dim chclr As TCHOOSECOLOR
chclr.lStructSize = Len(chclr)
' Color must get reference variable to receive result
' Flags can get reference variable or constant with bit flags
' Owner can take handle of owning window
If owner <> -1 Then chclr.hWndOwner = owner
' Assign color (default uninitialized value of zero is good default)
chclr.rgbResult = Color
' Mask out unwanted bits
Dim afMask As Long
afMask = CLng(Not (CC_ENABLEHOOK Or _
CC_ENABLETEMPLATE))
' Pass in flags
chclr.flags = afMask And (CC_RGBInit Or _
IIf(AnyColor, CC_AnyColor, CC_SolidColor) Or _
(-FullOpen * CC_FullOpen) Or _
(-DisableFullOpen * CC_PreventFullOpen))
' If first time, initialize to white
If fNotFirst = False Then InitColors
chclr.lpCustColors = VarPtr(alCustom(0))
' All other fields zero
m_lApiReturn = ChooseColor(chclr)
Select Case m_lApiReturn
Case 1
' Success
VBChooseColor = True
Color = chclr.rgbResult
Case 0
' Cancelled
VBChooseColor = False
Color = -1
Case Else
' Extended error
m_lExtendedError = CommDlgExtendedError()
VBChooseColor = False
Color = -1
End Select
End Function
Private Sub InitColors()
Dim i As Long
' Initialize with first 16 system interface colors
For i = 0 To 15
alCustom(i) = GetSysColor(i)
Next
fNotFirst = True
End Sub
Private Sub StrToBytes(ab() As Byte, S As String)
If IsArrayEmpty(ab) Then
' Assign to empty array
ab = StrConv(S, vbFromUnicode)
Else
Dim cab As Long
' Copy to existing array, padding or truncating if necessary
cab = UBound(ab) - LBound(ab) + 1
If Len(S) < cab Then S = S & String$(cab - Len(S), 0)
'If UnicodeTypeLib Then
' Dim st As String
' st = StrConv(s, vbFromUnicode)
' CopyMemoryStr ab(LBound(ab)), st, cab
'Else
CopyMemoryStr ab(LBound(ab)), S, cab
'End If
End If
End Sub
Private Function BytesToStr(ab() As Byte) As String
BytesToStr = StrConv(ab, vbUnicode)
End Function
Private Function IsArrayEmpty(va As Variant) As Boolean
Dim v As Variant
On Error Resume Next
v = va(LBound(va))
IsArrayEmpty = (Err <> 0)
End Function