Ok, I modified the private element in public element.
But i have again error message ...
That is my code :
Directly into the Form :
Public Sub Form_Load()
Module
End Sub
Public Sub Command1_Click()
Dim cc As CHOOSECOLORSTRUCT
Dim r As Long
Dim g As Long
Dim b As Long
With cc
'set the flags based on the check and option buttons
.flags = CC_ANYCOLOR
If Option2.Value = True Then .flags = .flags Or CC_FULLOPEN
If Option3.Value = True Then .flags = .flags Or CC_PREVENTFULLOPEN
If Check1.Value = 1 Then
.flags = .flags Or CC_RGBINIT
.rgbResult = Form1.BackColor
End If
'size of structure
.lStructSize = Len(cc)
'owner of the dialog
.hwndOwner = Me.HWND
'assign the custom colour selections
.lpCustColors = VarPtr(dwCustClrs(0))
End With
If ChooseColor(cc) = 1 Then
'assign the selected colour as the form background
Me.BackColor = cc.rgbResult
'bonus .. assure the text remains readable regardless of colour by splitting out the respective
'RGB values, and adjusting the text colour to contrast
Call GetRBGFromCLRREF(cc.rgbResult, r, g, b)
Call UpdateControlShadeSelection(r, g, b)
End If
End Sub
Public Sub UpdateControlShadeSelection(r As Long, g As Long, b As Long)
Dim ctlcolor As Long
Dim ctl As Control
'if the value of the colour passed (representing the current colour) is less than 128, show white text
'otherwise show black text
If (r < 128) And (g < 128) Or _
(g < 128) And (b < 128) Or _
(r < 128) And (b < 128) Then
ctlcolor = vbWhite
Else
ctlcolor = vbWindowText
End If
'set the option and check backcolor to the form backcolor, and the 'control's text to the contrasting shade
For Each ctl In Controls
If TypeOf ctl Is OptionButton Or _
TypeOf ctl Is CheckBox Then
ctl.BackColor = RGB(r, g, b)
ctl.ForeColor = ctlcolor
End If
Next
End Sub
Public Sub GetRBGFromCLRREF(ByVal clrref As Long, r As Long, g As Long, b As Long)
'pass a hex colour, return the rgb components
b = (clrref \ 65536) And &HFF
g = (clrref \ 256) And &HFF
r = clrref And &HFF
End Sub
Public Sub Command2_Click()
Unload Me
End Sub
And that is in the module
Declare PtrSafe Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (lpcc As CHOOSECOLORSTRUCT) As Long
Public Sub Module()
'initialize the custom colours
'with a series of gray shades
Dim cnt As Long
For cnt = 240 To 15 Step -15
dwCustClrs((cnt \ 15) - 1) = RGB(cnt, cnt, cnt)
Next
'initialize controls
Option1.Caption = "Display normally"
Option1.Value = True
Option2.Caption = "Display with Define Custom Colors open"
Option3.Caption = "Disable Define Custom Colors button"
Check1.Caption = "Specify initial colour is form BackColor"
Command1.Caption = "Choose Color"
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'static array to contain the custom
'colours selected by the user
Public dwCustClrs(0 To 15) As Long
'ChooseColor structure flag constants
Private Const CC_RGBINIT As Long = &H1
Private Const CC_FULLOPEN As Long = &H2
Private Const CC_PREVENTFULLOPEN As Long = &H4
Private Const CC_SOLIDCOLOR As Long = &H80
Private Const CC_ANYCOLOR As Long = &H100
Public Type CHOOSECOLORSTRUCT
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
End Sub
This module work but the error appears in the form on the line :
Public Sub Command1_Click()
Dim cc As CHOOSECOLORSTRUCT
With de message :
"Compilation error. User-defined type not defined."