开发者社区> 问答> 正文

VIS MFC的Static控件如何进行涂色?

已解决

想做一个选择颜色的对话框,已经按照大神的方法放好了static,着色又不会了。能不能给出具体的代码,谢谢!

展开
收起
51干警网 2016-02-15 11:22:11 2314 0
1 条回答
写回答
取消 提交回答
  • 阿里云论坛版主,QQ 1978638808
    采纳回答
    void CApp2Dlg::OnButton1() 
    {
        // TODO: Add your control notification handler code here
        CColorDialog colorDia;
         if (colorDia.DoModal() == IDOK)
         {
              m_color = colorDia.GetColor();
              GetDlgItem(IDC_STATIC_1)->InvalidateRect(NULL);
         }
    }
    
    HBRUSH CApp2Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
        HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
        m_brush.CreateSolidBrush(m_color);
        // TODO: Change any attributes of the DC here
        UpdateData(TRUE);
        if (pWnd->GetDlgCtrlID() == IDC_STATIC_1)
        {
            pDC->SetBkColor(m_color);
            pDC->SetBkMode(OPAQUE);
            return m_brush;
        }
    
        UpdateData(FALSE);
    
        // TODO: Return a different brush if the default is not desired
        return hbr;
    }
    2019-07-17 18:28:47
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载