Index of refa


Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (lpcc As CHOOSECOLOR_TYPE) As Long

Platforms

  • Windows 95: Supported.
  • Windows 98: Supported.
  • Windows NT: Requires Windows NT 3.1 or later.
  • Windows 2000: Supported.
  • Windows CE: Requires Windows CE 2.0 or later.

Description & Usage

ChooseColor opens a Choose Color common dialog box. All the information needed to create the dialog box, as well as the data returned from it, is stored in the structure passed as lpcc.

Return Value

If an error occured or the user pressed the Cancel button, the function returns 0 (use CommDlgExtendedError to get the error code). If the user successfully selected a color, the function returns a non-zero value.

Visual Basic-Specific Issues

None.

Parameters

lpcc
All the information needed to create the Choose Color common dialog box. If successful, the function then stores the user's color selection and list of custom colors into this structure as well.

Example

' This code is licensed according to the terms and conditions listed here. ' Display a Choose Color common dialog box.  The background ' color of Form1 will be set to the color the user selects.  Although the entire ' list of custom colors is initialized to black, this example stores the ' colors into an array which can be used again to save the user's custom ' color selections. Dim cc As CHOOSECOLOR_TYPE ' structure to pass data Dim hMem As Long  ' handle to the memory block to store the custom color list Dim pMem As Long  ' pointer to the memory block to store the custom color list Dim custcols(0 To 15) As Long  ' holds list of the 16 custom colors Dim c As Integer  ' counter variable Dim retval As Long  ' return value ' Initialize the list of custom colors to black. For c = 0 To 15  ' loop through each element   custcols(c) = 0  ' set each element to RGB color 0 (black) Next c ' Create a memory block and get a pointer to it. hMem = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, 64)  ' allocate sufficient memory block pMem = GlobalLock(hMem)  ' get a pointer to the block ' Copy the data inside the array into the memory block. CopyMemory ByVal pMem, custcols(0), 64  ' 16 elements * 4 bytes ' Store the initial settings of the Choose Color box. cc.lStructSize = Len(cc)  ' size of the structure cc.hwndOwner = Form1.hWnd  ' Form1 is opening the Choose Color box cc.hInstance = 0  ' not needed cc.rgbResult = Form1.BackColor  ' set default selected color to Form1's background color cc.lpCustColors = pMem  ' pointer to list of custom colors cc.Flags = CC_ANYCOLOR Or CC_RGBINIT  ' allow any color, use rgbResult as default selection cc.lCustData = 0  ' not needed cc.lpfnHook = 0  ' not needed cc.lpTemplateName = ""  ' not needed ' Open the Choose Color box.  If the user chooses a color, set Form1's ' background color to that color. retval = ChooseColor(cc) If retval <> 0 Then  ' success   ' Copy the possibly altered contents of the custom color list   ' back into the array.   CopyMemory custcols(0), ByVal pMem, 64   ' Set Form1's background color.   Form1.BackColor = cc.rgbResult End If ' Deallocate the memory blocks to free up resources. retval = GlobalUnlock(hMem) retval = GlobalFree(pMem)

Category

Common Dialog

Go back to the alphabetical Function listing.
Go back to the Reference section index.


Last Modified: August 14, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/c/choosecolor.html



Windows API Guide
Windows API Guide - Reference - Volume 1: Version 3.0 For the MS-DOS and PC-DOS Operating Systems
ISBN: B001V0KQIY
EAN: N/A
Year: 1998
Pages: 610

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net