Archived

This topic is now archived and is closed to further replies.

Centering a dialog box

This topic is 5381 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

O.k, I know next to 0 about windows programming. All my programming to date was cross platform, but for my game demo I chose to try windows specifically. So I want a nice little dialog box, to get resolution etc... from the user at startup. I went to VC6, drew the dialog, and then in my init, I called DialogBox(blah,blah,blah,blah) everything works well. The only thing is, my dialog box is at the upper left of my screen. How can I center it, or at least specify the coordinates where it appears?

Share this post


Link to post
Share on other sites
In your dialog callback procedure you could check for the WM_INITDIALOG message which is sent just before the dialog is displayed, and move the dialog then.

You can get the size of the dialog with the GetWindowRect function, set its position with SetWindowPos, and retrieve the screen width with EnumDisplaySettings.

I'm no Win32 API expert so there may be easier ways to do what you want, that's just one.

[edited by - Dobbs on March 24, 2003 5:07:44 PM]

Share this post


Link to post
Share on other sites
Ataru I don''t think so. As far as I can tell there''s no way to pass an initial position to DialogBox, and once the function begins execution it doesn''t return until the dialog is closed. So you can''t do


DialogBox(blah blah blah);
SetWindowPos(blah blah blah);


since by the second line the dialog is already displayed and gone. So as far as I can tell the only way to do it is in the dialog callback, and it takes a bit of work.

This is the reason people make windowing wrappers...

Share this post


Link to post
Share on other sites
Ugh, you''d think they''d make it easier huh? Well it''s no big deal, I just need a way to enter some input before the game begins, it would have been nice, but I don''t think it''s crucial.

Share this post


Link to post
Share on other sites
Actually it''s really great for you guys to mention that it''s done in the callbacks. I searched on the net with this information, and microsoft actually provides the code. I''ll try it out later, but it looks like it will work.

Thanks for the help, would have never known that you can do that kind of stuff in the callback.

Share this post


Link to post
Share on other sites
I have always used GetSystemMetrics( SM_CXSCREEN and SM_CYSCREEN ) then subtracted the width or height of the box and divided by two.

Then use the SetWindowPos...



Share this post


Link to post
Share on other sites