tags:

views:

43

answers:

3

I'm developing an MDI application, the primary document is maximized in the MDI frame. I create a non-modal dialog pop-up to display secondary information to the user while they work in the main window. However, when the user moves the pop-up it takes focus which is expected. The problem occurs when this window has focus and an event which generates an AfxMessageBox occurs in the mainframe. I would expect the AfxMessageBox to pop-up centered on the mainframe. Currently, it pops up centered on the non-modal dialog pop-up window which, by chance, had focus at that time.

Is there a way to force AfxMessageBox to always pop-up centered on the mainframe? Or at least force it to pop-up centered on the window in which it was called. For example, if in my non-modal dialog an error occurs, i would want the AfxMessageBox to appear centered on that dialog because it's intuitive that the error occurred there. Alternatively, if I'm working with the non-modal dialog and an error occurs in the mainframe or document then I would like the AfxMessageBox to appear centered on it's view/frame despite the fact that I'm currently working with the child window.

I hope that's clear enough.

A: 

Can you use instead standard ::MessageBox with first (parent) parameter equals to NULL. In this case desktop will be used as parent, so it would be centered on screen.

Dewfy
Thank you for the reply.
Dillyman
+2  A: 

Use the CWnd::MessageBox() method instead.

Hans Passant
I used this as a test and it worked perfectly. However, we are using Prof-UIS so I used their CExtMessageBox::DoMsgBox() to accomplish the same thing.
Dillyman
A: 

Keep using AfxMessageBox but override DoMessageBox of your CWinApp subclass. In your override do whatever you want to display a message box to the user using ::MessageBox() or even displaying a custom dialog box. This saves you from replacing calls to AfxMessageBox across your source code files.

mmonem
Thank you for the reply.
Dillyman