[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using OnClose to close multiple views

Posted on 2006-04-28
11
Medium Priority
?
174 Views
Last Modified: 2013-11-20
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();
}
0
Comment
Question by:mitesh114
  • 6
  • 2
8 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16561601
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?
0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 16561645
AFAIK you can't position a system message box.
HOWEVER you can cheat.  You can provide your own CDialog based message box and that you can position where you want.

You can use SetWindowPosition(NULL, iLeft, iTop, 0, 0, SWP_NOSIZE | SWP_NOZORDER) in the OnInitDialog of your custom dialog to position the dialog at co-ordinates iLeft, iTop.

You can also use
CRect rc;
pSomeWnd->GetWindowRect(&rc);  
now rc contains the screen co-ordinates of the rectangle encompasing the window pSomeWnd points to.


If you just require the dialog centering relative to a window then
void CenterWindow(
   CWnd* pAlternateOwner = NULL
);
 
Parameters
pAlternateOwner
Pointer to an alternate window relative to which it will be centered (other than the parent window).

0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16561774
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();
0
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!

 

Author Comment

by:mitesh114
ID: 16584581
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)
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16584849
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)
0
 

Author Comment

by:mitesh114
ID: 16585595
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...
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16666823
Is it sorted out now?
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16877054
I think he did adopt my suggestion.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

873 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