VB and VBA Users Source Code: Show the "Choose a Color" Common Dialog
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Show the "Choose a Color" Common Dialog
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Friday, November 17, 2000
Hits:
580
Category:
Windows API
Article:
To show the choose color common dialog, use the following function: Option Explicit Private Declare Function ChooseColorA Lib "comdlg32.dll" (pChoosecolor As tChooseColor) As Long Private Declare Function GetActiveWindow Lib "user32" () As Long Private Type tChooseColor lStructSize As Long hwndOwner 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 'Purpose : Shows the Choose Color Dialog 'Inputs : N/A 'Outputs : Returns -1 if the user pressed cancel, else returns the selected color 'Author : bakera 'Date : 17/11/2000 10:19 'Notes : 'Revisions : 'Assumptions : Function ShowColor() As Long Dim tColor As tChooseColor Dim Custcolor(16) As Long Dim lReturn As Long, lThisColor As Long Dim abytCustomColors(0 To 16 * 4 - 1) As Byte For lThisColor = LBound(abytCustomColors) To UBound(abytCustomColors) abytCustomColors(lThisColor) = 0 Next tColor.lStructSize = Len(tColor) tColor.hwndOwner = GetActiveWindow 'or Me.hwnd in VB tColor.hInstance = 1 'or App.hInstance in VB 'Convert the custom colors to Unicode tColor.lpCustColors = StrConv(abytCustomColors, vbUnicode) tColor.flags = 0 'Show the dialog If ChooseColorA(tColor) <> 0 Then ShowColor = tColor.rgbResult Else ShowColor = -1 End If End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder