我把dialog涂了颜色,但是static控件的背景没法去掉。OnCtlColor这个函数不会用。

解决方案 »

  1.   

    HBRUSH CLogToolDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // set edit properities
        if(pWnd->GetDlgCtrlID() == IDC_EDIT_LOG)
        {
            static HBRUSH hbrEdit = ::CreateSolidBrush(RGB(255, 255, 255));
            pDC->SetBkColor(RGB(255, 255, 255));
            pDC->SetTextColor(RGB(0, 0, 255));
            return hbrEdit;
        }

    return hbr;
    } // end of OnCtlColor()
      

  2.   

    The WM_CTLCOLOR message has been replaced by more specific notifications in 32-bit versions of Windows. These replacements include the following:
    WM_CTLCOLORBTN 
    WM_CTLCOLOREDIT 
    WM_CTLCOLORDLG 
    WM_CTLCOLORLISTBOX 
    WM_CTLCOLORSCROLLBAR 
    WM_CTLCOLORSTATIC 要改Static的话,建议用WM_CTLCOLORSTATIC,或者自己继承一个Static,然后写OnPaint
      

  3.   

    HBRUSH CTest6Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    switch(nCtlColor)
    {
    case CTLCOLOR_STATIC:
    if(pWnd->GetDlgCtrlID() == IDC_STATIC2)
    {
    if(GetFocus() == (CStatic*)GetDlgItem(IDC_STATIC2))
    {
    static HBRUSH hbrEdit = ::CreateSolidBrush( RGB(255, 255, 255) );
    pDC->SetBkColor(TRANSPARENT);
    pDC->SetTextColor( RGB(255, 0, 0) );
    return hbrEdit;
    }
    }
    } // TODO: Return a different brush if the default is not desired
    return hbr;
    }