我用 AppWizard 生成时,最后一步 View的基类 我选着 CFormView.然后屏幕上出现了一个Form。我现在想改变该Form的颜色。怎么办?
我在CFormView上加了一个事件函数(WM_CTLCOLOR) pDC->SetBkColor(RGB(255,0,0));
运行,发现只改变了Form上的文字颜色。我想把Form的背景也该了。怎么办?

解决方案 »

  1.   

    首先,给对话基类增加一成员变量CBursh : class CMyFormView : public CFormView { … private : CBrush m_ brush ; // background brush … } ; 其次, 在类的构造函数中将刷子初始化为所需要的背景颜色。 CMyFormView : : CMyFormView ( ) { // Initialize background brush . m_brush .CreateSolidBrush (RGB ( 0, 0, 255 ) ) } 最后,使用ClassWizard处理WM_CTLCOLOR消息并返回一个用来绘画对话背景的刷子句柄。注意:由于当重画对话控件时也要调用该函数,所以要检测nCtlColor参量。 HBRUSH CMyFormView : : OnCtlColor (CDC* pDC , CWnd*pWnd , UINT nCtlColor ) { // Determine if drawing a dialog box . If we are , return +handle to //our own background brush . Otherwise let windows handle it . if (nCtlColor = = CTLCOLOR _ DLG ) return (HBRUSH) m_brush .GetSafeHandle ( ) ; return CFormView : : OnCtlColor (pDC, pWnd , nCtlColor ); } 
      

  2.   

    BOOL CYourView::OnEraseBkgnd(CDC* pDC)
    {
    CRect r;
    GetClientRect(r);
    pDC->FillSolidRect(r, RGB(255,0,0));
    return TRUE;
    }
      

  3.   

    BOOL CYourView::OnEraseBkgnd(CDC* pDC)
    {
    CRect r;
    GetClientRect(r);
    pDC->FillSolidRect(r, RGB(255,0,0));
    return TRUE;
    }
      

  4.   

    在类列表里找到这个类,右键点击此类选择add windows message haldle,有下角选择window(默认为dialog),然后在左侧选择wm_erasebkgnd,添加此项处理函数,然后在里面用
    CRect rectclient, rect;
    GetClientRect (&rectclient); //获取客户区大小
    pDC->FillSolidRect(rectclient, RGB(192,192,192));//crBackGroundColor);
    注意最后是return TRUE;封掉return CDialog::OnEraseBkgnd(pDC);