Pour utiliser le dialogue ChooseColor de Windows, à partir du
code, on peut utiliser la fonction API ChooseColor.
Si vous ne désirez obtenir que la valeur de la couleur choisie par
l'utilisateur, simplement changer la déclaration de la fonction comme suit,
dans modColorPicker:
Public Function DialogColor(ctl As Control) As Long
et alors, depuis votre formulaire, le code peut ressembler à:
Private Sub CmdChooseBackColor_Click()
Me.textCtl.BackColor = DialogColor(Me.textCtl)
End Sub
Private Type COLORSTRUC
lStructSize As Long
hwnd As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
Flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Const CC_SOLIDCOLOR = &H80
Private Declare Function ChooseColor _
Lib "comdlg32.dll" Alias "ChooseColorA" _
(pChoosecolor As COLORSTRUC) As Long
Public Function aDialogColor(prop As Property) As Boolean
Dim x As Long, CS As COLORSTRUC, CustColor(16) As Long
CS.lStructSize = Len(CS)
CS.hwnd = hWndAccessApp
CS.Flags = CC_SOLIDCOLOR
CS.lpCustColors = String$(16 * 4, 0)
x = ChooseColor(CS)
If x = 0 Then
prop = RGB(255, 255, 255) ' White
aDialogColor = False
Exit Function
Else
prop = CS.rgbResult
End If
aDialogColor = True
End Function