Share via


CMFCColorPickerCtrl Class

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

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

See Also

Reference

Hierarchy Chart

CMFCColorDialog Class

Other Resources

MFC Classes