Solved

Question on controlling buttons from different dialogs.

Posted on 2002-03-03
5
166 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
  • 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 100 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

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

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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