Click here to Skip to main content
Click here to Skip to main content

Color CButton, CEdit, and CDialog using CAdvancedComponent

By , 3 Nov 2008
Rate this:
Please Sign up or sign in to vote.

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

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

Comments and Discussions

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