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

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Nov 7, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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!
m_pDlg->Create(IDD_MYDIALOG);
m_pDlg->ShowWindow(SW_SHOW);

To construct a modal dialog:

Assumption: CMyDialog is derived from CBaseDialog.

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

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!

Advertisement

Warning:

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.