我派生了一个CStatic类,在CDialog中使用正常。能改变颜色,但在formview中却不行,我该怎么办?OnSetCursor()也不能用。

解决方案 »

  1.   

    不可能吧...我刚才特地试了一下...没问题呀... 
    HBRUSH CAsdfasdfView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here
     if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)
       {
          // Set the text color to red
          pDC->SetTextColor(RGB(55, 55, 0));      // Set the background mode for text to transparent 
          // so background will show thru.
          pDC->SetBkMode(TRANSPARENT);      // Return handle to our CBrush object
          hbr = CreateSolidBrush(RGB(255,0,0));
       }
    return hbr;
    }
      

  2.   

    派生的还要这样处理?????没必要吧...直接在派生类里paint就行了
      

  3.   

    若要改变CFromView继承类的背景颜色,下面是一个范例代码:HBRUSH CMyFormView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {switch (nCtlColor) 
    { case CTLCOLOR_BTN: 
    case CTLCOLOR_STATIC: 
    { pDC->SetBkMode(TRANSPARENT); 
    //不加任何处理或设置背景为透明} 
    case CTLCOLOR_DLG: 
    { CBrush* back_brush; 
    COLORREF color; 
    color = (COLORREF) GetSysColor(COLOR_BTNFACE); 
    back_brush = new CBrush(color); 
    return (HBRUSH) (back_brush->m_hObject);}} return(CFormView::OnCtlColor(pDC, pWnd, nCtlColor));}