MFC颜色对话框的使用

可以使用CColorDialog打开选择如下颜色对话框


                    image

其构造函数如下:
 
CColorDialog(
 
 COLORREF clrInit = 0//默认颜色,为空则为RGB(0,0,0)(黑色)
   DWORD dwFlags = 0//介绍如下
   CWnd* pParentWnd = NULL //父窗口
);
Flags:
CC_ANYCOLOR
Causes the dialog box to display all available colors in the set of basic colors.
CC_ENABLEHOOK
Enables the hook procedure specified in the lpfnHook member of this structure. This flag is used only to initialize the dialog box.
CC_ENABLETEMPLATE
Indicates that the hInstance and lpTemplateName members specify a dialog box template to use in place of the default template. This flag is used only to initialize the dialog box.
CC_ENABLETEMPLATEHANDLE
Indicates that the hInstance member identifies a data block that contains a preloaded dialog box template. The system ignores the lpTemplateName member if this flag is specified. This flag is used only to initialize the dialog box.
CC_FULLOPEN
Causes the dialog box to display the additional controls that allow the user to create custom colors. If this flag is not set, the user must click the Define Custom Color button to display the custom color controls. 全部展开颜色对话框,从而可以自己指定颜色
CC_PREVENTFULLOPEN
Disables the Define Custom Color button.
CC_RGBINIT
Causes the dialog box to use the color specified in the rgbResult member as the initial color selection.
使用指定的颜色作为对话框打开时的初始颜色(可以在构造函数指定初始颜色或使用会话框的m_cc.rgbResult 来指定
CC_SHOWHELP
Causes the dialog box to display the Help button. The hwndOwner member must specify the window to receive the HELPMSGSTRING registered messages that the dialog box sends when the user clicks the Help button.
CC_SOLIDCOLOR
Causes the dialog box to display only solid colors in the set of basic colors.

 

最后可以通过GetColor()函数得到COLORREF类型的颜色,再用GetXValue得到具体的颜色值。

 

如使用如下

void CEnvParaTab::OnBnClickedButtonClearcolor()
{
    // TODO: Add your control notification handler code here
    COLORREF color = RGB(m_dColorRed*255, m_dColorGreen*255, m_dColorBlue*255);
    CColorDialog cdlg(color, CC_FULLOPEN | CC_RGBINIT); // 设置默认颜色
    if(cdlg.DoModal() == IDOK)
        color = cdlg.GetColor();
   
    m_dColorRed = GetRValue(color)/255.0;
    m_dColorGreen = GetGValue(color)/255.0;
    m_dColorBlue = GetBValue(color)/255.0;
    UpdateData(FALSE);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值