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!
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!

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



Comments

  • Thanks dude - I'll be having some fun with this ;-)

    Posted by Legacy on 09/11/2003 12:00am

    Originally posted by: Roddy

    The modeless code works without any hassle - had modeless dlgs working within an old app within 10 minutes of downloading your class.
    
    

    To anyone who says they are having probs with this, its has to be your source and not the source of the author - sorry guys :-)

    ++R

    Reply
  • Modeless/Modal Dialogs with custom color...

    Posted by Legacy on 11/14/2002 12:00am

    Originally posted by: NeLoDave

    This rocks! I've been looking for something like this for a while now.

    Reply
  • How to disable the menu item which triggers the modeless dialog?

    Posted by Legacy on 01/19/2000 12:00am

    Originally posted by: TEH KOK HOW

    I manage to create a modeless dialog using the BaseDialog class but there is one problem here. How could I possibly disable the menuitem which triggers the modeless dialog?
    
    I use the codes here but to no avail:

    void CScoreBoardApp::OnUpdateViewScoreboard(CCmdUI* pCmdUI)
    {
    CMenu * pMenu = pCmdUI->m_pMenu;
    if (pMenu != NULL)
    pMenu->EnableMenuItem(ID_VIEW_SCOREBOARD,
    m_bBusy ? MF_BYCOMMAND|MF_GRAYED : MF_BYCOMMAND|MF_ENABLED);
    m_bBusy=FALSE;
    }

    or

    void CScoreBoardApp::OnViewScoreboard()
    {
    CMainFrame *pFrame =
    (CMainFrame *) AfxGetMainWnd();
    CMenu * pMenu = pFrame->GetMenu();
    if (pMenu != NULL)
    pMenu->EnableMenuItem(ID_VIEW_SCOREBOARD,
    m_bBusy ? MF_BYCOMMAND|MF_GRAYED : MF_BYCOMMAND|MF_ENABLED);
    m_bBusy=FALSE;
    }
    Thanks.

    Reply
  • dialog box background colors

    Posted by Legacy on 01/01/1999 12:00am

    Originally posted by: Allan Latham

    OK this works greats but....

    How do I get the static text controls within the dialog box
    to take on the dialog box background color as their background?

    I only need to do this once at dialog box initialization.

    Thanks

    Allan.


    01/01/99

    OK worked out how to do it.

    It needs just a simple change to the BaseDialog class.

    I will see if I can upload it to you.

    Thanks again

    Allan.

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

Top White Papers and Webcasts

  • Live Event Date: March 19, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT The 2015 Enterprise Mobile Application Survey asked 250 mobility professionals what their biggest mobile challenges are, how many employees they are equipping with mobile apps, and their methods for driving value with mobility. Join Dan Woods, Editor and CTO of CITO Research, and Alan Murray, SVP of Products at Apperian, as they break down the results of this survey and discuss how enterprises are using mobile application management and private …

  • The mobile market is white hot. Building a well-crafted product development plan that addresses market research, strategy, design, and development will provide the greatest chance for success. Each phase of an app's lifecycle is critical to the its overall success and feeds into the next step of the process of product development for the app. This white paper examines the five key phases of mobile app creation, one by one, to understand how they work together to help create a successful mobile app.

Most Popular Programming Stories

More for Developers

RSS Feeds

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