• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

Question on controlling buttons from different dialogs.

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
s6192221
Asked:
s6192221
  • 2
  • 2
1 Solution
 
Roshan DavisCommented:
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
 
s6192221Author Commented:
hey thanks... i'm gonna try it out when i'm home after work... thanks! await my results :)
0
 
DanRollinsCommented:
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
 
s6192221Author Commented:
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
 
DanRollinsCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now