Click here to Skip to main content
13,350,483 members (63,609 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 3 Nov 2008

Color CButton, CEdit, and CDialog using CAdvancedComponent

, 3 Nov 2008
Rate this:
Please Sign up or sign in to vote.
Using CAdvancedComponent to change the background, foreground, and other colors on CButton, CEdit, and CDialog.

Sample Image 1


CAdvancedButton, CAdvancedEdit, and CAdvancedDialog are MFC controls respectively derived from CButton, CEdit, and CDialog.

These classes implement the CAdvancedComponent virtual class, and offer functions to change background and foreground colors.

Using the Code

To integrate the CAdvancedComponent classes into your application, please follow the steps below:

Using the CAdvancedButton

  1. Add AdvancedComponent.h, AdvancedButton.h, and AdvancedButton.cpp to your project.
  2. Include "AdvancedButton.h" in the dialog class' header.
  3. Declare the button in the dialog class. For example:
  4. CAdvancedButton adBtn1;
  5. Initialize the button in the dialog class' OnInitDialog function:
  6. adBtn1.SubclassDlgItem(IDC_BUTTON1, this, RED, GREEN);
  7. Eventually change the draw form:
  8. adBtn1.SetDrawType(DRAW_ELLIPSE); // or DRAW_RECT
  9. Eventually change the colors:
  10. adBtn1.SetColors(RED);

Using the CAdvancedEdit

  1. Add AdvancedComponent.h, AdvancedEdit.h, and AdvancedEdit.cpp to your project.
  2. Include "AdvancedEdit.h" in the dialog class' header.
  3. Declare the edit in the dialog class. For example:
  4. CAdvancedEdit adEdit1;
  5. Initialize the edit in the dialog class' OnInitDialog function:
  6. adEdit1.SubclassDlgItem(IDC_EDIT1, this);
  7. Change the colors:
  8. adEdit1.SetBackGround(YELLOW);

Using the CAdvancedDialog

  1. Add AdvancedComponent.h, AdvancedDialog.h, and AdvancedDialog.cpp to your project.
  2. Include "AdvancedDialog.h" in the dialog class' header.
  3. Replace the base class from CDialog to CAdvancedDialog in your dialog class' header.
  4. In the .cpp file, in the constructor, replace CDialog by CAdvancedDialog.
  5. In the .cpp file, replace CDialog::DoDataExchange by CAdvancedDialog::DoDataExchange.
  6. If they exist, do the same thing for OnInitDialog and the other inherited functions.
  7. In the .cpp file, replace "BEGIN_MESSAGE_MAP(CTest, CDialog)" by "BEGIN_MESSAGE_MAP(CTest, CAdvancedDialog)".
  8. Use CAdvancedDialog's functions.

If you want the CAdvancedDialog children to change automatically, create the child dialog using a pointer on the main dialog as the first parameter:

class CMyDialogClass : public CAdvancedDialog {

CMyDialogClass myDialogBow(this);

UML class diagram

UML Diagram


  • November 2008: First version distributed on CodeProject.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
France (Metropolitan) France (Metropolitan)
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 4 Nov 2008
Article Copyright 2008 by Loack_
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid