Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows
Visual Basic > Common Dialogs sample source codes
Show the 'Choose a Color' Common Dialog
Show the 'Choose a Color' Common Dialog 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 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
Privacy Policy
|
Link to Us
|
Links