change the background color of a dialog box mfc

win32 dialog box background color
onctlcolor
how to change the button background color in mfc
wm_ctlcolor
windows dialog box color
change background color of static text mfc
mfc dialog box
wm_ctlcolordlg

I'm trying to change the background color of a dialog box (win 7, vs2010,c++). I tried to catch WM_CTLCOLOR ,WM_ERASEBKGND and change the color. I manged to change in this way the backgroung color, but when the window is finish to upload itself, the color is back to default but I noticed that the frame is in the right color. I think that I'm changing the window and not the dialog box or something like that. I'm doing this with WTL (not AFX).

What should I do?

Try this:

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
    CAboutDlg();

// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

// Implementation
protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    ON_WM_ERASEBKGND()
    //}}AFX_MSG_MAP

END_MESSAGE_MAP()




BOOL CAboutDlg::OnEraseBkgnd(CDC* pDC)
{
    CRect rect;
    GetClientRect(&rect);
    CBrush myBrush(RGB(255, 255, 255));    // dialog background color
    CBrush *pOld = pDC->SelectObject(&myBrush);
    BOOL bRes  = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY);
    pDC->SelectObject(pOld);    // restore old brush
    return bRes;                       // CDialog::OnEraseBkgnd(pDC);
}

And have a look here ... and most important : here

change the background color of a dialog box mfc, Try this: ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public:  I'm new to the MFC programming. I need to change the back ground color of the edit boxes in my application. I hope the code provided in the first reply in this thread will do that. But I'm confused with the phrase "Add the WM_CTLCOLR Message handler for the dialog". Can any one please explain me how can I add that message handler? Thank You.

Hi the above answer will work only if you don't have tab inside dialog box it will color background of dialog box other the tab portion. for tab portion you have to create new derived class with base class CTabCtrl.

Setting the Dialog Box's Background Color, The color you set is used for only the specified dialog box. See codexpert blog for an example. See also. Working with Dialog Boxes in MFC Note that in some controls, part of the control (surrounding the text) is the correct color for the normal window background, white or dialog-box-color, but the rest of the control is the chosen MYCOLOR background. While this is an improvement for the static controls, it is definitely not an improvement for the other controls.

The better way will be to override WM_CTLCOLOR, background of controls such as STATIC will be fill with your color too.

BEGIN_MESSAGE_MAP(YourDlg, CDialogEx)
    ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
...
HBRUSH YourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    return (HBRUSH)GetStockObject(WHITE_BRUSH);
}

Changing the background color of dialog box - MSDN, In MFC dialog i want to change the background color can u please tell me how to change the background color. Thursday, September 17, 2009  Color setting, call the dialog box provided by the system to complete the selection of brush and brush color. At the same time, using this dialog box can realize the custom color. The brush width setting dialog box is a dialog box set by yourself. Input the corresponding brush width to change the brush width.

Changing the background color of a dialog, If you want to change the background color of your dialog box, it is a very simple. In your CTestDlg header file, declare a member variable from  I'm trying to change the background color of a dialog box (win 7, vs2010,c++). I tried to catch WM_CTLCOLOR ,WM_ERASEBKGND and change the color. I manged to change in this way the backgroung color, but when the window is finish to upload itself, the color is back to default but I noticed that the frame is in the right color.

VC++ Example: Change the background color of a dialog, CDialog , The MFC extension library that offers Visual C++ developers a complete set If you want to change the background color of your dialog box, it is a very simple. Click the Text Color swatch box to reveal the color palette. Choose any color you like. The color you select fills the color swatch box but won’t change the text color on your page until you click the Apply or OK button. Click the Background Color swatch box to reveal the color palette.

How to Change the color of an MFC, For MFC applications using the document/view model, // this is //Make sure to return the Brush color should be same as Dialog Background color How To Change Window Background Color with Foundation Classes[^] VC++ Example: Change the background color of a dialog, CDialog, OnCtlColor. If you want to change the background color of your dialog box, it is a very simple. In your CTestDlg header file, declare a member variable from CBrush:

Comments
  • just entering your title in google, or changing the end to wtl shows pretty promising results
  • Already checked that but I didn't find anything promising
  • The question is supposed to show whatever you already tried and how that failed so answers can be specific
  • Your comment about using Google is now irrelevant as this question is the top link when searching how to change an mfc dialog box colour
  • What are all these commented out lines (e.g. // AFX_MSG_MAP(CAboutDlg)) for?
  • @aquirdturtle these comments are generated by old versions of VS so the wizzard knows where to insert code.