| title | CMFCColorPickerCtrl Class | Microsoft Docs | |||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ms.custom | ||||||||||||||||||||
| ms.date | 11/04/2016 | |||||||||||||||||||
| ms.reviewer | ||||||||||||||||||||
| ms.suite | ||||||||||||||||||||
| ms.technology |
|
|||||||||||||||||||
| ms.tgt_pltfrm | ||||||||||||||||||||
| ms.topic | reference | |||||||||||||||||||
| f1_keywords |
|
|||||||||||||||||||
| dev_langs |
|
|||||||||||||||||||
| helpviewer_keywords |
|
|||||||||||||||||||
| ms.assetid | b9bbd03c-beb0-4b55-9765-9985fd05e5dc | |||||||||||||||||||
| caps.latest.revision | 33 | |||||||||||||||||||
| author | mikeblome | |||||||||||||||||||
| ms.author | mblome | |||||||||||||||||||
| manager | ghogen | |||||||||||||||||||
| translation.priority.ht |
|
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/satuaration/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
CMFCColorPickerCtrlclass is inherited from theCButtonclass). -
Insert a member variable that is associated with the new button control into your dialog box class. Then change the variable type from
CButtontoCMFCColorPickerCtrl. -
Insert the
WM_INITDIALOGmessage handler for the dialog box class. In the handler, set the type, palette, and initial selected color of theCMFCColorPickerCtrlcontrol.
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.
[!code-cppNVC_MFC_NewControls#4]
[!code-cppNVC_MFC_NewControls#5]
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);
[in] pDC
Pointer to a device context.
[in] rect
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);
[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.
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);
[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.
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);
[in] Color
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);
[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.
Changes the hue of the currently selected color.
void SetHue(double Hue);
[in] Hue
A hue value.
Changes the luminance of the currently selected color.
void SetLuminance(double Luminance);
[in] Luminance
A luminance value.
Sets the width of the luminance bar in the color picker control.
void SetLuminanceBarWidth(int w);
[in] w
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);
[in] ref
An RGB color value.
Call this method when the color picker control is initialized.
Sets the current color palette.
void SetPalette(CPalette* pPalette);
[in] pPalette
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);
[in] Saturation
A saturation value.
Sets the type of color picker control to display.
void SetType(COLORTYPE colorType);
[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.
To specify a color picker control type, call this method before the Windows control is created.
