Solved

Question on controlling buttons from different dialogs.

Posted on 2002-03-03
5
162 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now