A Base Dialog Class for Modal/Modeless Dialog with Custom Background Color


This base dialog class (CBaseDialog) handles:

1) Modal dialog
2) Modeless dialog
3) Custom Background color
4) ON_UPDATE_COMMAND_UI available for dialog controls (I used Tim McColl's method).

How to use CBaseDialog class in your project?

To construct a modeless dialog:

Let's say CMyDialog is derived from CBaseDialog, and m_pDlg is declared as a CDialog* in a class where you plan to instanticate the dialog.

m_pDlg = new CMyDialog; 
m_pDlg.SetModelessFlag(true); // voila! this is all it takes to make your dlg modeless!

To construct a modal dialog:

Assumption: CMyDialog is derived from CBaseDialog.

CMyDialog dlg; // you can see, business is as usual:-)

To change dialog background:

You can specify background color in your OnInitDialog:

SetBackgroundColor(RGB(0, 0, 128)); // you can really make your dialog fansy now

You can add a ON_UPDATE_COMMAND_UI for a control in the dialog to set states for the control ( see Tim McColl's Use ON_UPDATE_COMMAND_UI in the dialog section). See how it is done in the demo project.

Have fun, folks!


ON_UPDATE_COMMAND_UI handler does not work if the dialog is modeless. If anyone has a solution to this, please let me know so that the source can be updated.

Download demo project - 33KB

Download source - 3KB


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date