CMFCColorPickerCtrl 类
CMFCColorPickerCtrl
类提供用于选择颜色的控件的功能。
语法
class CMFCColorPickerCtrl : public CButton
成员
公共构造函数
名称 | 描述 |
---|---|
CMFCColorPickerCtrl::CMFCColorPickerCtrl |
构造 CMFCColorPickerCtrl 对象。 |
公共方法
名称 | 描述 |
---|---|
CMFCColorPickerCtrl::GetColor |
检索用户选择的颜色。 |
CMFCColorPickerCtrl::GetHLS |
检索用户选择的颜色的色调、亮度和饱和度值。 |
CMFCColorPickerCtrl::GetHue |
检索用户选择的颜色的色调分量。 |
CMFCColorPickerCtrl::GetLuminance |
检索用户选择的颜色的亮度分量。 |
CMFCColorPickerCtrl::GetSaturation |
检索用户选择的颜色的饱和度分量。 |
CMFCColorPickerCtrl::SelectCellHexagon |
将当前颜色设置为由指定的 RGB 颜色分量或指定的单元格六边形定义的颜色。 |
CMFCColorPickerCtrl::SetColor |
将当前颜色设置为指定的 RGB 颜色值。 |
CMFCColorPickerCtrl::SetHLS |
将当前颜色设置为指定的 HLS 颜色值。 |
CMFCColorPickerCtrl::SetHue |
更改当前所选颜色的色调分量。 |
CMFCColorPickerCtrl::SetLuminance |
更改当前所选颜色的亮度分量。 |
CMFCColorPickerCtrl::SetLuminanceBarWidth |
设置颜色选取器控件中亮度条的宽度。 |
CMFCColorPickerCtrl::SetOriginalColor |
设置初始选定颜色。 |
CMFCColorPickerCtrl::SetPalette |
设置当前调色板。 |
CMFCColorPickerCtrl::SetSaturation |
更改当前所选颜色的饱和度分量。 |
CMFCColorPickerCtrl::SetType |
设置要显示的颜色选取器控件的类型。 |
受保护方法
名称 | 描述 |
---|---|
CMFCColorPickerCtrl::DrawCursor |
在显示指向所选颜色的光标之前由框架调用。 |
注解
标准颜色是从六边形调色板中选择的,并从亮度条中选择自定义颜色,其中使用红色/绿色/蓝色表示法或色调/饱和度/亮度表示法指定颜色。
下图描绘了多个 CMFCColorPickerCtrl
对象。
CMFCColorPickerCtrl
支持两对样式。 和HEX
HEX_GREYSCALE
样式适用于标准颜色选择。 和PICKER
LUMINANCE
样式适用于自定义颜色选择。
执行以下步骤,以便将 CMFCColorPickerCtrl
控件合并到对话框中:
如果使用 ClassWizard,请将新按钮控件插入到对话框模板中(因为
CMFCColorPickerCtrl
类继承自CButton
类)。将与新按钮控件关联的成员变量插入到对话框类中。 然后,将变量类型从
CButton
更改为CMFCColorPickerCtrl
。插入对话框类的
WM_INITDIALOG
消息处理程序。 在处理程序中,设置CMFCColorPickerCtrl
控件的类型、调色板和初始选定颜色。
继承层次结构
CObject
CCmdTarget
CWnd
CButton
CMFCColorPickerCtrl
要求
标头:afxcolorpickerctrl.h
CMFCColorPickerCtrl::CMFCColorPickerCtrl
构造 CMFCColorPickerCtrl
对象。
CMFCColorPickerCtrl();
返回值
注解
CMFCColorPickerCtrl::DrawCursor
在显示指向所选颜色的光标之前由框架调用。
virtual void DrawCursor(
CDC* pDC,
const CRect& rect);
参数
pDC
[in] 指向设备上下文的指针。
rect
[in] 指定所选颜色周围的矩形区域。
注解
需要更改指向所选颜色的光标的形状时重写此方法。
CMFCColorPickerCtrl::GetColor
检索用户选择的颜色。
COLORREF GetColor() const;
返回值
选定颜色的 RGB 值。
注解
CMFCColorPickerCtrl::GetHLS
检索用户选择的颜色的色调、亮度和饱和度值。
void GetHLS(
double* hue,
double* luminance,
double* saturation);
参数
hue
[out] 指向接收色调信息的 double 类型的变量的指针。
luminance
[out] 指向接收亮度信息的 double 类型的变量的指针。
saturation
[out] 指向接收饱和度信息的 double 类型的变量的指针。
注解
CMFCColorPickerCtrl::GetHue
检索用户选择的颜色的色调分量。
double GetHue() const;
返回值
选定颜色的色调分量。
注解
CMFCColorPickerCtrl::GetLuminance
检索用户选择的颜色的亮度分量。
double GetLuminance() const;
返回值
选定颜色的亮度分量。
注解
CMFCColorPickerCtrl::GetSaturation
检索用户选择的颜色的饱和度值。
double GetSaturation() const;
返回值
选定颜色的饱和度分量。
注解
CMFCColorPickerCtrl::SelectCellHexagon
将当前颜色设置为由指定的 RGB 颜色分量或指定的单元格六边形定义的颜色。
void SelectCellHexagon(
BYTE R,
BYTE G,
BYTE B);
BOOL SelectCellHexagon(
int x,
int y);
参数
R
[in] 红色分量。
G
[in] 绿色分量。
B
[in] 蓝色分量。
x
[in] 光标的 x 坐标,该坐标指向单元格六边形。
y
[in] 光标的 y 坐标,该坐标指向单元格六边形。
返回值
此方法的第二个重载始终返回 FALSE。
备注
此方法的第一个重载将当前颜色设置为与颜色选择控件指定的红色、绿色和蓝色分量相对应的颜色。
此方法的第二个重载将当前颜色设置为指定光标位置指向的单元格六边形的颜色。
CMFCColorPickerCtrl::SetColor
将当前颜色设置为指定的 RGB 颜色值。
void SetColor(COLORREF Color);
参数
Color
[in] RGB 颜色值。
注解
CMFCColorPickerCtrl::SetHLS
将当前颜色设置为指定的 HLS 颜色值。
void SetHLS(
double hue,
double luminance,
double saturation,
BOOL bInvalidate=TRUE);
参数
hue
[in] 色调值。
luminance
[in] 亮度值。
saturation
[in] 饱和度值。
bInvalidate
[in] TRUE
强制窗口立即更新为新颜色;否则,为 FALSE
. 默认为 TRUE
。
注解
CMFCColorPickerCtrl::SetHue
更改当前所选颜色的色调。
void SetHue(double Hue);
参数
Hue
[in] 色调值。
注解
CMFCColorPickerCtrl::SetLuminance
更改当前所选颜色的亮度。
void SetLuminance(double Luminance);
参数
Luminance
[in] 亮度值。
注解
CMFCColorPickerCtrl::SetLuminanceBarWidth
设置颜色选取器控件中亮度条的宽度。
void SetLuminanceBarWidth(int w);
参数
w
[in] 亮度条的宽度,以像素度量。
备注
使用此方法可调整亮度条的大小,该亮度条位于颜色选取器控件的“自定义”选项卡上。 该 w
参数指定亮度条的新宽度。 如果超过工作区宽度的四分之三,则忽略宽度值。
CMFCColorPickerCtrl::SetOriginalColor
设置初始选定颜色。
void SetOriginalColor(COLORREF ref);
参数
ref
[in] RGB 颜色值。
备注
初始化颜色选取器控件时调用此方法。
CMFCColorPickerCtrl::SetPalette
设置当前调色板。
void SetPalette(CPalette* pPalette);
参数
pPalette
[in] 指向调色板的指针。
备注
调色板定义颜色选取器控件中显示的颜色数组。
CMFCColorPickerCtrl::SetSaturation
更改当前所选颜色的饱和度。
void SetSaturation(double Saturation);
参数
Saturation
[in
] 饱和度值。
注解
CMFCColorPickerCtrl::SetType
设置要显示的颜色选取器控件的类型。
void SetType(COLORTYPE colorType);
参数
colorType
[in] 颜色选取器控件类型。
类型由 CMFCColorPickerCtrl::COLORTYPE
枚举定义。 可能的类型是LUMINANCE
,PICKER
HEX
和HEX_GREYSCALE
。 默认类型为 PICKER
。
注解
若要指定颜色选取器控件类型,请在创建 Windows 控件之前调用此方法。