我想修改CDialog的WNDCLASS,以使得CDialog的背景色为某种值。
该对话框是非模式的;
但是发现AfxRegisterWndClass 函数只能搭配CWnd::Create使用,而CDialog::Create似乎无法使用AfxRegisterWndClass的返回值。
该对话框是非模式的;
但是发现AfxRegisterWndClass 函数只能搭配CWnd::Create使用,而CDialog::Create似乎无法使用AfxRegisterWndClass的返回值。
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);
}
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;
}
{
pDC->SelectObject (m_BkBrush);
return TRUE;
//return FALSE;
}
这样的话也不行,要么在OnPaint里面Rectangle,要么就没有效果。
{
// 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;
}
{
// Return handle to our CBrush object
hbr = m_brush; }CTLCOLOR_DLG改成你的对话框ID