Changing the Background and Static Text Color of your MFC Dialog box

By default, VC++ doesn’t have a backcolor or forecolor control properties unlike other visual programming languages such as VB or VFP. But you can change the dialog box text and back color by following these simple steps.

1. Start VC++ by clicking the start button>All Programs>Microsoft Visual Studio 6.0> Microsoft Visual C++ 6.0.
2. Click File>New>Select MFC AppWizard (exe)>Type the Project name>Click Ok>Select Dialog based>Click Finish.
3. Right click your dialog box>In the Class name list box>Select CprojectnameAPP>Double click the InitInstance member function.

The following codes will appear:

CBkColorApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CBkApp initialization
BOOL CBkColorApp::InitInstance()
{
AfxEnableControlContainer();

// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
//  the specific initialization routines you do not need.

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic();// Call this when linking to MFC statically
#endif
4. Type the following before or after the line AfxEnableControlContainer(). Change the numbers inside the oval brace to create different background or text colors.
SetDialogBkColor(RGB(255,255,255),RGB(255,255,255));
5. The first RGB is for the backcolor and the other one is for the text.
6. Click the run icon to view the result.