Muokkaa

Jaa


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/saturation/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.

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

pDC
[in] Pointer to a device context.

rect
[in] 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

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

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

saturation
[out] 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

R
[in] The red color component.

G
[in] The green color component.

B
[in] The blue color component.

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

y
[in] 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

Color
[in] 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

hue
[in] A hue value.

luminance
[in] A luminance value.

saturation
[in] A saturation value.

bInvalidate
[in] 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

Hue
[in] A hue value.

Remarks

CMFCColorPickerCtrl::SetLuminance

Changes the luminance of the currently selected color.

void SetLuminance(double Luminance);

Parameters

Luminance
[in] A luminance value.

Remarks

CMFCColorPickerCtrl::SetLuminanceBarWidth

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

void SetLuminanceBarWidth(int w);

Parameters

w
[in] 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

ref
[in] 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

pPalette
[in] 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

Saturation
[in] A saturation value.

Remarks

CMFCColorPickerCtrl::SetType

Sets the type of color picker control to display.

void SetType(COLORTYPE colorType);

Parameters

colorType
[in] 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