CMFCColorPickerCtrl Class
The CMFCColorPickerCtrl
class provides functionality for a control that is used to select colors.
class CMFCColorPickerCtrl : public CButton
Name | Description |
---|---|
CMFCColorPickerCtrl::CMFCColorPickerCtrl |
Constructs a CMFCColorPickerCtrl object. |
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. |
Name | Description |
---|---|
CMFCColorPickerCtrl::DrawCursor |
Called by the framework before a cursor that points to the selected color is displayed. |
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.
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:
If you use the ClassWizard, insert a new button control into your dialog box template (because the
CMFCColorPickerCtrl
class is inherited from theCButton
class).Insert a member variable that is associated with the new button control into your dialog box class. Then change the variable type from
CButton
toCMFCColorPickerCtrl
.Insert the
WM_INITDIALOG
message handler for the dialog box class. In the handler, set the type, palette, and initial selected color of theCMFCColorPickerCtrl
control.
CObject
CCmdTarget
CWnd
CButton
CMFCColorPickerCtrl
Header: afxcolorpickerctrl.h
Constructs a CMFCColorPickerCtrl
object.
CMFCColorPickerCtrl();
Called by the framework before a cursor that points to the selected color is displayed.
virtual void DrawCursor(
CDC* pDC,
const CRect& rect);
pDC
[in] Pointer to a device context.
rect
[in] Specifies a rectangular area around the selected color.
Override this method when you need to change the shape of the cursor that points to the selected color.
Retrieves the color that the user selects.
COLORREF GetColor() const;
The RGB value of the selected color.
Retrieves the hue, luminance and saturation values of the color that the user selects.
void GetHLS(
double* hue,
double* luminance,
double* saturation);
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.
Retrieves the hue component of the color that the user selects.
double GetHue() const;
The hue component of the selected color.
Retrieves the luminance component of the color that the user selects.
double GetLuminance() const;
The luminance component of the selected color.
Retrieves the saturation value of the color that the user selects.
double GetSaturation() const;
The saturation component of the selected color.
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);
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.
The second overload of this method always returns FALSE.
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.
Sets the current color to the specified RGB color value.
void SetColor(COLORREF Color);
Color
[in] An RGB color value.
Sets the current color to the specified HLS color value.
void SetHLS(
double hue,
double luminance,
double saturation,
BOOL bInvalidate=TRUE);
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
.
Changes the hue of the currently selected color.
void SetHue(double Hue);
Hue
[in] A hue value.
Changes the luminance of the currently selected color.
void SetLuminance(double Luminance);
Luminance
[in] A luminance value.
Sets the width of the luminance bar in the color picker control.
void SetLuminanceBarWidth(int w);
w
[in] The width of the luminance bar measured in pixels.
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.
Sets the initial selected color.
void SetOriginalColor(COLORREF ref);
ref
[in] An RGB color value.
Call this method when the color picker control is initialized.
Sets the current color palette.
void SetPalette(CPalette* pPalette);
pPalette
[in] Pointer to a color palette.
The color palette defines the array of colors that is presented in the color picker control.
Changes the saturation of the currently selected color.
void SetSaturation(double Saturation);
Saturation
[in
] A saturation value.
Sets the type of color picker control to display.
void SetType(COLORTYPE colorType);
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
.
To specify a color picker control type, call this method before the Windows control is created.