Avatar of mitesh114
mitesh114

asked on 

Using OnClose to close multiple views

Hi all,

I have an application where i have three views.  The mainframe calls two views (slaveframes) which are identical and a child view.  

I have a button on the slaveframes of the views to Logout which effectively call the OnClose method of the MainFrame.  When I either hit the File|Exit or the logout in the slaveframe, I get a message box to logout.  This appears in the slaveframe ie the view that called it.  However when i hit the X in the top right hand corner, the logout box appears in the childview.  I'm not entirely sure why this is happening as I am overriding the OnClose for the File|Exit, the X and also the Logout button.  Any help on how to fix this would be greatly appreciated as it is very annoying!

Below is my code for the OnClose in the ChildView, SlaveFrame and MainFrame:
void CMainFrame::OnClose()
{
      if( AfxMessageBox( IDS_LOGOUT_SURE, MB_ICONQUESTION | MB_YESNO ) == IDYES )
      {
            KillTimer( TIMER_ID_RECONNECT );

            //m_Events.Event( CARGO_USEREVENT_LOGOUT );
            m_Connection.Disconnect();
            m_HardwareConnection.Disconnect();
            RapiLogOff();
            CFrameWnd::OnClose();
      }
}

void CSlaveFrame::OnLogout( void )
{
      OnClose();
}

void CSlaveFrame::OnClose( void )
{
      pMainFrame->OnClose();
}
System Programming

Avatar of undefined
Last Comment
AndyAinscow
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

I am not too clear on exactly what you describe but it sounds like the message box is appearing central to the view that has the focus when you use the button BUT central to the main app when you use the 'x' on a view or the frame.  Is that correct?
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

ps.
Don't forget you can specify the parent of a dialog as follows
CMyDlg dlg(this);
dlg.DoModal();

or
CMyDlg dlg(pSomeOtherWnd);
dlg.DoModal();
Avatar of mitesh114
mitesh114

ASKER

Thanks Andy.  What you said in your first comment was correct: "message box is appearing central to the view that has the focus when you use the button BUT central to the main app when you use the 'x' on a view or the frame".

I'm going to give what you suggested a try! :o)
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

I forgot to mention this
int MessageBox(          HWND hWnd,
    LPCTSTR lpText,
    LPCTSTR lpCaption,
    UINT uType
);


Using the (non-MFC) MessageBox may be suitable for your requirements.  This might center the message box relative to the main window of the app, irrespective of the active view.

eg.
MessageBox(AfxGetMainWnd()->GetSafeHwnd(), "message", "caption", MB_YESNO|MB_ICONQUESTION)
Avatar of mitesh114
mitesh114

ASKER

Hi Andy,

The non-MFC message box did not work.  it actually makes the message box appear on the main window even when you hit the logout buttons on the slaves!  i'm still working on the dialog...
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Is it sorted out now?
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

I think he did adopt my suggestion.
System Programming
System Programming

Kernel and system programming is the process of creating the software necessary for a computer or device to function and operate other programs. Some operating systems (such as Microsoft Windows) are proprietary, but others, such as the various Linux distributions, are open source.

41K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo