简体   繁体   中英

How to force AfxMessageBox to center on mainframe and not whatever child window that currently has focus

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.

请改用CWnd :: MessageBox()方法。

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM