Centering Messageboxes

Centering Messageboxes

By default,message boxes appear at the center of the screen. Is it possible to center message boxes with respect to the parent window?
Dialog boxes have the option DS_CENTER to do the same.Can something similar be done for message boxes?

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Sure - just pass your window's handle as the hwnd argument. If you don't have it "handy", use GetForegroundWindow.


Steve - Intel Developer Support

I tried the following code and the message box still remained in the center of the screen and not my window.

hwnd = GetForegroundWindow()
Do i have to change any other option?
I also noticed that the DS_CENTER option centers the dialog box on the screen and not with respect to the parent window.
Can that be changed too?

Yes, you can hook WH_CBT and change the position there.


For all of posterity. If you know your code is correct
(ie have sent the correct parent window handle to the
Messagebox function) & you find your Messageboxes
still remain in the center of your desktop, you may
try checking the display properties of your video card/
display driver.

In my case, (I have 2 monitors - w/ a M*trox Millenium G550)
I right-clicked on my M*trox Qu*ckdesk system tray icon,
selected "Multi-Display Controls", & toggled "Use CenterPOPUP"
checkbox & then toggled the "In parent program window" radio

more keywords:

HTH somebody

Leave a Comment

Please sign in to add a comment. Not a member? Join today