Programming |  Windows Programming |  CHOOSECOLOR

CHOOSECOLOR

The CHOOSECOLOR structure contains information the ChooseColor function uses to initialize the Color dialog box. After the user closes the dialog box, the system returns information about the user's selection in this structure.

Syntax

    typedef struct {
        DWORD lStructSize;
        HWND hwndOwner;
        HWND hInstance;
        COLORREF rgbResult;
        COLORREF *lpCustColors;
        DWORD Flags;
        LPARAM lCustData;
        LPCCHOOKPROC lpfnHook;
        LPCTSTR lpTemplateName;
    } CHOOSECOLOR, *LPCHOOSECOLOR;

Members

Structure Information


CHOOSECOLOR cc;                 // common dialog box structure 
static COLORREF acrCustClr[16]; // array of custom colors 
HWND hwnd;                      // owner window
HBRUSH hbrush;                  // brush handle
static DWORD rgbCurrent;        // initial color selection

// Initialize CHOOSECOLOR 
ZeroMemory(&cc, sizeof(cc));
cc.lStructSize = sizeof(cc);
cc.hwndOwner = hwnd;
cc.lpCustColors = (LPDWORD) acrCustClr;
cc.rgbResult = rgbCurrent;
cc.Flags = CC_FULLOPEN | CC_RGBINIT;
 
if (ChooseColor(&cc)==TRUE) {
    hbrush = CreateSolidBrush(cc.rgbResult);
    rgbCurrent = cc.rgbResult; 
}