Compartir a través de


CMFCColorPickerCtrl Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CMFCColorPickerCtrl Class.

The CMFCColorPickerCtrl class provides functionality for a control that is used to select colors.

Syntax

class CMFCColorPickerCtrl : public CButton  

Members

Public Constructors

Name Description
CMFCColorPickerCtrl::CMFCColorPickerCtrl Constructs a CMFCColorPickerCtrl object.

Public Methods

Name Description
CMFCColorPickerCtrl::GetColor Retrieves the color that the user selects.
CMFCColorPickerCtrl::GetHLS Retrieves the hue, luminance and saturation values of the color that the user selects.
CMFCColorPickerCtrl::GetHue Retrieves the hue component of the color that the user selects.
CMFCColorPickerCtrl::GetLuminance Retrieves the luminance component of the color that the user selects.
CMFCColorPickerCtrl::GetSaturation Retrieves the saturation component of the color that the user selects.
CMFCColorPickerCtrl::SelectCellHexagon Sets the current color to the color defined by the specified RGB color components or the specified cell hexagon.
CMFCColorPickerCtrl::SetColor Sets the current color to the specified RGB color value.
CMFCColorPickerCtrl::SetHLS Sets the current color to the specified HLS color value.
CMFCColorPickerCtrl::SetHue Changes the hue component of the currently selected color.
CMFCColorPickerCtrl::SetLuminance Changes the luminance component of the currently selected color.
CMFCColorPickerCtrl::SetLuminanceBarWidth Sets the width of the luminance bar in the color picker control.
CMFCColorPickerCtrl::SetOriginalColor Sets the initial selected color.
CMFCColorPickerCtrl::SetPalette Sets the current color palette.
CMFCColorPickerCtrl::SetSaturation Changes the saturation component of the currently selected color.
CMFCColorPickerCtrl::SetType Sets the type of color picker control to display.

Protected Methods

Name Description
CMFCColorPickerCtrl::DrawCursor Called by the framework before a cursor that points to the selected color is displayed.

Remarks

Standard colors are selected from a hexagonal color palette, and custom colors are selected from a luminance bar where colors are specified using either red/green/blue notation or hue/satuaration/luminance notation.

The following illustration depicts several CMFCColorPickerCtrl objects.

CMFCColorPickerCtrl dialog box

The CMFCColorPickerCtrl supports two pairs of styles. The HEX and HEX_GREYSCALE styles are appropriate for standard color selection. The PICKER and LUMINANCE styles are appropriate for custom color selection.

Perform the following steps to incorporate the CMFCColorPickerCtrl control into your dialog box:

  1. If you use the ClassWizard, insert a new button control into your dialog box template (because the CMFCColorPickerCtrl class is inherited from the CButton class).

  2. Insert a member variable that is associated with the new button control into your dialog box class. Then change the variable type from CButton to CMFCColorPickerCtrl.

  3. Insert the WM_INITDIALOG message handler for the dialog box class. In the handler, set the type, palette, and initial selected color of the CMFCColorPickerCtrl control.

Example

The following example demonstrates how to configure a CMFCColorPickerCtrl object by using various methods in the CMFCColorPickerCtrl class. The example demonstrates how to set the type of the picker control, and how to set its color, hue, luminance, and saturation. The example is part of the New Controls sample.

    CMFCColorPickerCtrl m_wndLum;
 // CPalette m_palSys
    // set the type of the color picker control
    m_wndLum.SetType(CMFCColorPickerCtrl::LUMINANCE);
    m_wndLum.SetPalette(&m_palSys);
    // set the color, hue, luminance and saturation of the color picker control
    m_wndLum.SetColor(RGB(0, 255, 0));
    m_wndLum.SetHue(0.5);
    m_wndLum.SetLuminance(2.5);
    m_wndLum.SetLuminanceBarWidth(10);
    m_wndLum.SetSaturation(0.5);

Inheritance Hierarchy

CObject

CCmdTarget

CWnd

CButton

CMFCColorPickerCtrl

Requirements

Header: afxcolorpickerctrl.h

CMFCColorPickerCtrl::CMFCColorPickerCtrl

Constructs a CMFCColorPickerCtrl object.

CMFCColorPickerCtrl();

Return Value

Remarks

CMFCColorPickerCtrl::DrawCursor

Called by the framework before a cursor that points to the selected color is displayed.

virtual void DrawCursor(
    CDC* pDC,  
    const CRect& rect);

Parameters

[in] pDC
Pointer to a device context.

[in] rect
Specifies a rectangular area around the selected color.

Remarks

Override this method when you need to change the shape of the cursor that points to the selected color.

CMFCColorPickerCtrl::GetColor

Retrieves the color that the user selects.

COLORREF GetColor() const;  

Return Value

The RGB value of the selected color.

Remarks

CMFCColorPickerCtrl::GetHLS

Retrieves the hue, luminance and saturation values of the color that the user selects.

void GetHLS(
    double* hue,  
    double* luminance,  
    double* saturation);

Parameters

[out] hue
Pointer to a variable of type double that receives hue information.

[out] luminance
Pointer to a variable of type double that receives luminance information.

[out] saturation
Pointer to a variable of type double that receives saturation information.

Remarks

CMFCColorPickerCtrl::GetHue

Retrieves the hue component of the color that the user selects.

double GetHue() const;  

Return Value

The hue component of the selected color.

Remarks

CMFCColorPickerCtrl::GetLuminance

Retrieves the luminance component of the color that the user selects.

double GetLuminance() const;  

Return Value

The luminance component of the selected color.

Remarks

CMFCColorPickerCtrl::GetSaturation

Retrieves the saturation value of the color that the user selects.

double GetSaturation() const;  

Return Value

The saturation component of the selected color.

Remarks

CMFCColorPickerCtrl::SelectCellHexagon

Sets the current color to the color defined by the specified RGB color components or the specified cell hexagon.

void SelectCellHexagon(
    BYTE R,  
    BYTE G,  
    BYTE B);

 
BOOL SelectCellHexagon(
    int x,  
    int y);

Parameters

[in] R
The red color component.

[in] G
The green color component.

[in] B
The blue color component.

[in] x
The x-coordinate of the cursor, which points to a cell hexagon.

[in] y
The y-coordinate of the cursor, which points to a cell hexagon.

Return Value

The second overload of this method always returns FALSE.

Remarks

The first overload of this method sets the current color to the color that corresponds to the color selection control's specified red, green, and blue color components.

The second overload of this method sets the current color to the color of the cell hexagon that is pointed to by the specified cursor location.

CMFCColorPickerCtrl::SetColor

Sets the current color to the specified RGB color value.

void SetColor(COLORREF Color);

Parameters

[in] Color
An RGB color value.

Remarks

CMFCColorPickerCtrl::SetHLS

Sets the current color to the specified HLS color value.

void SetHLS(
    double hue,  
    double luminance,  
    double saturation,  
    BOOL bInvalidate=TRUE);

Parameters

[in] hue
A hue value.

[in] luminance
A luminance value.

[in] saturation
A saturation value.

[in] bInvalidate
TRUE to force the window to immediately update to the new color; otherwise, FALSE. The default is TRUE.

Remarks

CMFCColorPickerCtrl::SetHue

Changes the hue of the currently selected color.

void SetHue(double Hue);

Parameters

[in] Hue
A hue value.

Remarks

CMFCColorPickerCtrl::SetLuminance

Changes the luminance of the currently selected color.

void SetLuminance(double Luminance);

Parameters

[in] Luminance
A luminance value.

Remarks

CMFCColorPickerCtrl::SetLuminanceBarWidth

Sets the width of the luminance bar in the color picker control.

void SetLuminanceBarWidth(int w);

Parameters

[in] w
The width of the luminance bar measured in pixels.

Remarks

Use this method to resize the luminance bar, which is on the Custom tab of the color picker control. The w parameter specifies the new width of the luminance bar. The width value is ignored if it exceeds three-fourths of the client area width.

CMFCColorPickerCtrl::SetOriginalColor

Sets the initial selected color.

void SetOriginalColor(COLORREF ref);

Parameters

[in] ref
An RGB color value.

Remarks

Call this method when the color picker control is initialized.

CMFCColorPickerCtrl::SetPalette

Sets the current color palette.

void SetPalette(CPalette* pPalette);

Parameters

[in] pPalette
Pointer to a color palette.

Remarks

The color palette defines the array of colors that is presented in the color picker control.

CMFCColorPickerCtrl::SetSaturation

Changes the saturation of the currently selected color.

void SetSaturation(double Saturation);

Parameters

[in] Saturation
A saturation value.

Remarks

CMFCColorPickerCtrl::SetType

Sets the type of color picker control to display.

void SetType(COLORTYPE colorType);

Parameters

[in] colorType
A color picker control type.

The types are defined by the CMFCColorPickerCtrl::COLORTYPE enumeration. The possible types are LUMINANCE, PICKER, HEX and HEX_GREYSCALE. The default type is PICKER.

Remarks

To specify a color picker control type, call this method before the Windows control is created.

See Also

Hierarchy Chart
Classes
CMFCColorDialog Class