怎么CDialog 没有setbkcolor之类的函数啊?想用CBrush又不知道,CBrush 怎么设置颜色。

解决方案 »

  1.   

    映射WM_CTLCOLOR
    HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here

      hbr = ::CreateSolidBrush(RGB(255,255,0));//这里可以写你要的颜色!

    // TODO: Return a different brush if the default is not desired
    return hbr;
    }
      

  2.   

    除此之外,还有什么其他方法吗??  因为使用了换肤的DLL后,这功能好像就无效了。  能放一个控件 上去专门绘图吗??  用什么控件比较好??
      

  3.   

    那就映射WM_PAINT
    void CAboutDlg::OnPaint() 
    {
    CPaintDC dc(this); // device context for painting

    // TODO: Add your message handler code here

    CBrush brush;
    brush.CreateSolidBrush(RGB(255,0,0));//颜色!
    CRect rct;
    GetClientRect(&rct);
    dc.FillRect(&rct,&brush); // Do not call CDialog::OnPaint() for painting messages
    }
      

  4.   

    handwolf(初学者)的方法暗藏杀机,会造成GDI资源的泄漏!!
    brush.CreateSolidBrush(RGB(255,0,0));//就是这句
    要把画刷定义成员变量。
      

  5.   

    直接在
    CXXXApp::InitInstance函数中加入
    SetDialogBkColor(RGB(204, 163, 220),RGB(46, 21, 55) ); 
    就可以了。
      

  6.   

    to bigelm(枯燥着快乐着):
      把泄露的原因说给我听听。
      

  7.   

    CXXXApp::InitInstance函数中加入
    SetDialogBkColor();在Dlg.cpp里面响应 
    映射WM_CTLCOLOR
    HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
      hbr = ::CreateSolidBrush(RGB(255,255,0));//这里可以写你要的颜色! return hbr;
    }
      

  8.   

    这段时间正在做一个产品的终端界面显示,我在界面中也做过,把我实现的代码拷给你看看:
        定义画刷:
       CBrush m_beijingbrush1;
    CBrush m_beijingbrush;
        首先,在对话框OnInitDialog()函数中初始化画刷: 
        m_beijingbrush.CreateSolidBrush(RGB(142, 193, 232)); // bq-9生成主对话框背景一绿色刷子
     
        m_beijingbrush1.CreateSolidBrush(RGB(142, 193, 232)); // bq-9生成透过主对话框背景的一绿色刷子
        其次,为对话框类加一个OnCtlColor()函数(在类的Add windows message handler中添加这个函数),我的代码是:
    HBRUSH CZhbusDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)    在这个函数中添加代码,我的代码是:
       if (nCtlColor ==CTLCOLOR_DLG)
          return m_beijingbrush;  //返加绿色刷子   if (nCtlColor==CTLCOLOR_STATIC)
       {
         pDC->SetTextColor(RGB(48,24,141));//设置静态static的文字颜色//   pDC->SetBkColor(RGB(137, 181, 184));   //设置静态static的文字背景颜色yuan bq     pDC->SetBkColor(RGB(142, 193, 232));   //bq-9
       }
       if (nCtlColor==CTLCOLOR_EDIT)
    {
          pDC->SetTextColor(RGB(141,32,145));//设置edit框的文字颜色//    pDC->SetBkColor(RGB(132, 69, 165));   //设置edit框的文字背景颜色bq-1
          pDC->SetBkColor(RGB(142, 193, 232));   //bq-9
       }

     return m_beijingbrush1;   就3个地方,自己理解啊!!