[RESOLVED] creating custom colors before opening the commondialog box
Hai,
I've been looking around a bit but couldn't find anything about this.
I want to create/build some custom colors (programmaticly) before the commondialog box is opened.
the objective is to let the user choose either one of the standard colors or 1 of the 6 colors used in their logo.
Is it possible and how to approach this?
Thanks in Advance
Re: creating custom colors before opening the commondialog box
Here's an API solution that doesn't require the Common Dialog Control.
VB Code:
Private Declare Function ChooseColorAPI _
Lib "comdlg32.dll" Alias "ChooseColorA" ( _
pChoosecolor As CHOOSECOLOR) As Long
Private Type CHOOSECOLOR
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 String
End Type
Public Function ShowColor() As Long
Dim cc As CHOOSECOLOR
Dim lReturn As Long
Dim CustomColors(15) As Long
Dim i As Integer
'Set the custom colors in the CustomColors array
CustomColors(0) = vbRed
CustomColors(1) = vbGreen
CustomColors(2) = vbYellow
'and so on
cc.lStructSize = Len(cc)
cc.hwndOwner = Me.hWnd
cc.hInstance = 0
cc.lpCustColors = VarPtr(CustomColors(0))
cc.flags = 0
lReturn = ChooseColorAPI(cc)
If lReturn <> 0 Then
ShowColor = cc.rgbResult
Else
'User clicked the Cancel button so we return -1 instead of a color
ShowColor = -1
End If
End Function
Re: creating custom colors before opening the commondialog box
Thanks I will play around with it
Re: creating custom colors before opening the commondialog box
Quote:
Originally Posted by Joacim Andersson
Here's an API solution that doesn't require the Common Dialog Control.
VB Code:
Private Declare Function ChooseColorAPI _
Lib "comdlg32.dll" Alias "ChooseColorA" ( _
pChoosecolor As CHOOSECOLOR) As Long
Private Type CHOOSECOLOR
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 String
End Type
Public Function ShowColor() As Long
Dim cc As CHOOSECOLOR
Dim lReturn As Long
Dim CustomColors(15) As Long
Dim i As Integer
'Set the custom colors in the CustomColors array
CustomColors(0) = vbRed
CustomColors(1) = vbGreen
CustomColors(2) = vbYellow
'and so on
cc.lStructSize = Len(cc)
cc.hwndOwner = Me.hWnd
cc.hInstance = 0
cc.lpCustColors = VarPtr(CustomColors(0))
cc.flags = 0
lReturn = ChooseColorAPI(cc)
If lReturn <> 0 Then
ShowColor = cc.rgbResult
Else
'User clicked the Cancel button so we return -1 instead of a color
ShowColor = -1
End If
End Function
I am preparing my own color definition routine (maybe add-ins). I have only Visual Basic Editor - Version 6.3. This code writes me an error. How I should change part of the code? I do not understand what this code should do.
Boris