Microsoft KB Archive/98201

= How To Change Dialog Box Background Color in MFC 2.0 or Later =

Article ID: 98201

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.51

 Microsoft Visual C++ 1.52 Professional Edition</li></ul>

 Microsoft Visual C++ 1.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 2.2</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q98201

<div class="notice_section">

<div class="summary_section">

SUMMARY
An application developed with the Microsoft Foundation Classes (MFC) version 2.0 or later can change the background color of its dialog boxes by calling the SetDialogBkColor member function in the CWinApp class.

<div class="moreinformation_section">

MORE INFORMATION
SetDialogBkColor requires two COLORREF values as parameters. The first parameter specifies the dialog box background color; the second specifies the text color for a control in a dialog box. The application calls SetDialogBkColor in the InitInstance member function of the CWinApp class. For more information on the SetDialogBkColor function, please refer to the &quot;Class Library Reference Guide, Volume 1,&quot; or to the online Help file.

The application can use the RGB macro to supply the requested colors. The following sample code demonstrates this technique: BOOL CTheApp::InitInstance {     TRACE(&quot;HELLO WORLD\n&quot;);

// Change colors to red and green. SetDialogBkColor(RGB(192, 0, 19), RGB(19, 192, 0));

m_pMainWnd = new CMainWindow; m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow;

return TRUE; } The SetDialogBkColor function changes the colors of all dialog boxes in an application. If each dialog box requires a different background color, process the WM_CTLCOLOR message and return a brush that Windows can use to paint the dialog box background.

Keywords: kbhowto kbuidesign kbdlg KB98201

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.