Question on controlling buttons from different dialogs.

Posted on 2002-03-03
Medium Priority
Last Modified: 2013-11-20

Let say we have 2 dialogs namely A and B where A is the main menu and B is a login dialog. Both are modal dialogs and I would like to enable and disable buttons which resides in Dialog A from Dialog B depending on whether the login is successful or not. The question is how can I access or gain control of buttons in Dialog A from Dialog B itself?

I'm working on Windows XP Pro using MSVC 6.0

Any help would be very much appreciated!
Question by:s6192221
  • 2
  • 2
LVL 23

Expert Comment

by:Roshan Davis
ID: 6838539
Becoz of ur both dialogs r Modal, u can't directly access these dialogs from one another.
Add Public functions to both dialogs.
As u mentioned ur purpose, I understand that first the login dialog will popup, right..?

So keep some private members on the dialog, that stores the current selected options, these options can be accessed from outside by its public functions

By getting this values, u can set to the other dialog by its public functions,

On this dialogs ( Named B ), InitDialog, u can Enable, or diable ur child controls by
EnableWindow function.


Author Comment

ID: 6838636
hey thanks... i'm gonna try it out when i'm home after work... thanks! await my results :)
LVL 49

Expert Comment

ID: 6841117
Rather than having your Login dialog call functions in your Main dialog, just remember that there is no need to disable anything in Main because the user can't click anything in it until the Logon Dlg has popped down.  For instance, you must have code like this:

   CLogonDlg dlg;
   int nRet= dlg.DoModal();

just add code like this...

BOOL fEnableItems= FALSE; // assume login failed
if (nRet == IDOK ) {
      if ( dlg.m_dLoginSucceeded ) {
            fEnableItems= TRUE;
GetDlgItem(ID_WootWoot)->EnableWindow( fEnableItems );
GetDlgItem(ID_FooBaz)->EnableWindow( fEnableItems );

In other words, you can have logic in the Logon dialog that checks the validity of the login and sets a member variable (i called it m_fLogonSucceeded) to TRUE.  Then when the DoModal() returns, you can check that variable and if it is not TRUE, then you can disable selected items in the Main dialog.

-- Dan

Author Comment

ID: 6844183
Dan -> I'm using exactly the method u've mentioned before the posting... I'm interested to know how can i gain control of the dialog items from child dialogs.
LVL 49

Accepted Solution

DanRollins earned 400 total points
ID: 6845944
Pass Use GetParent and coerce the CWnd* into a pointer to the parent window, then access its variables and functions ate will:

        CMainDlg* pMain= (CMainDlg*)GetParent();
        pMain->GetDlgItem( blah blah )->EnableWindow(FALSE);
        pMain->m_ctlTree->AddItem(blah blagh );
        ... etc ...

Or pass in a pointer and use that, as suggested by roshmon.

Are you certain that you need to control the parent dialog while the child modal dialog is active?  Remember, the user cannot interact with it at all (although the user might be able to see changes you make, if the child is not covering it completely...)

-- Dan

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you are looking for an automated solution for backup single or multiple Office 365 user mailboxes to Outlook data file, then you can use Kernel Office 365 Backup & Restore tool. Go through the video to check out the steps to backup single or mult…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question