Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Color CButton, CEdit, and CDialog using CAdvancedComponent

0.00/5 (No votes)
3 Nov 2008 1  
Using CAdvancedComponent to change the background, foreground, and other colors on CButton, CEdit, and CDialog.

Sample Image 1

Introduction

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);
    adBtn1.SetBackGround(YELLOW);
    adBtn1.SetForeGround(BLUE);

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);
    adEdit1.SetForeGround(BLUE);
    adEdit1.SetTextBackGround(RED);

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);
myDialogBow.DoModal();

UML class diagram

UML Diagram

History

  • November 2008: First version distributed on CodeProject.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here