?
Solved

Question on controlling buttons from different dialogs.

Posted on 2002-03-03
5
Medium Priority
?
170 Views
Last Modified: 2013-11-20
Hi,

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!
0
Comment
Question by:s6192221
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
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.

GOOD LUCK
0
 

Author Comment

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

Expert Comment

by:DanRollins
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
0
 

Author Comment

by:s6192221
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.
0
 
LVL 49

Accepted Solution

by:
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:

CChildDlg::OnWhatever()
{
        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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

770 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