본문 바로가기

Windows/MFC

CDialog (Changing the background color of a dialog)

Link : http://www.codeguru.com/forum/showthread.php?t=394738&highlight=dialog+background

// m_bmpMyBitmap : CBitmap member variable
[code]
BOOL CSMS_WIZARDView::OnEraseBkgnd(CDC* pDC)
{
    // Declare variables
    CRect rectBackground;

    // Get client rect
    GetClientRect(rectBackground);
    
    // Background color should be white
    pDC->FillSolidRect(rectBackground, RGB(226, 233, 245));
    
    // Get paint field
    CDC dcMem;
    dcMem.CreateCompatibleDC(pDC);                
    CBitmap * pOldBitmap = dcMem.SelectObject(&m_bmpMyBitmap);

    // Draw bitmap
    pDC->BitBlt(0, 0, rectBackground.right, rectBackground.bottom, &dcMem, 0, 0, SRCCOPY);

    // Select original object
    dcMem.SelectObject(pOldBitmap);
    dcMem.DeleteDC();

    return TRUE;
}[/code]