To call Windows ChooseColor dialog from code, we can use the ChooseColor
API function.
If you want this function to simply return the value of the Color the user selected
from the Dialog, then just change the function declaration in modColorPicker to something like:
Public Function DialogColor(ctl As Control) As Long
Then call it from your Form with code like:
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
|