我想修改CDialog的WNDCLASS,以使得CDialog的背景色为某种值。
该对话框是非模式的;
但是发现AfxRegisterWndClass  函数只能搭配CWnd::Create使用,而CDialog::Create似乎无法使用AfxRegisterWndClass的返回值。

解决方案 »

  1.   

    http://topic.csdn.net/t/20000831/06/27641.html
      

  2.   

    // alter the styles of the main frame window
    BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
       // Create a window without min/max buttons or sizable border
       cs.style = WS_OVERLAPPED | WS_SYSMENU | WS_BORDER;   // Size the window to 1/3 screen size and center it
       cs.cy = ::GetSystemMetrics(SM_CYSCREEN) / 3;
       cs.cx = ::GetSystemMetrics(SM_CXSCREEN) / 3;
       cs.y = ((cs.cy * 3) - cs.cy) / 2;
       cs.x = ((cs.cx * 3) - cs.cx) / 2;    return CFrameWnd::PreCreateWindow(cs);
    }
      

  3.   

    对话框是特定的窗口类,当然不能另外注册。修改对话框背景可以重载WM_CTLCOLOR消息或者WM_ERASEBKGND自绘。
      

  4.   

    OnCtlColor函数一跑就推出,有个什么Exception
    HBRUSH CLoginPage::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    //HBRUSH hbr = CLoginPage::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here
    //if(CTLCOLOR_DLG ==nCtlColor)
    //{
    // return m_BkBrush ;
    //}
    // TODO: Return a different brush if the default is not desired
    HBRUSH hbr = CLoginPage::OnCtlColor(pDC, pWnd, nCtlColor);
    return hbr;
    }
      

  5.   

    CLoginPage::OnEraseBkgnd(CDC *pDC)
    {
    pDC->SelectObject (m_BkBrush);
    return TRUE;
    //return FALSE;
    }
    这样的话也不行,要么在OnPaint里面Rectangle,要么就没有效果。
      

  6.   

    HBRUSH CZilchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
       // Call the base class implementation first! Otherwise, it may
       // undo what we're trying to accomplish here.
       HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);   // Are we painting the IDC_MYSTATIC control? We can use
       // CWnd::GetDlgCtrlID() to perform the most efficient test.
       if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)
       {
          // Set the text color to red
          pDC->SetTextColor(RGB(255, 0, 0));      // Set the background mode for text to transparent 
          // so background will show thru.
          pDC->SetBkMode(TRANSPARENT);      // Return handle to our CBrush object
          hbr = m_brush;
       }   return hbr;
    }
      

  7.   

    改成 if ( pWnd->GetDlgCtrlID() == CTLCOLOR_DLG )
         { 
          // Return handle to our CBrush object
          hbr = m_brush;     }CTLCOLOR_DLG改成你的对话框ID