You are here:

C++/Opening a dialog box in the upper center of the page.

Advertisement


Question
Hi Eddie,

I am using Visual C++ 6.

Since it is somewhat tall, I would like to have a dialog box open in the upper-center of the screen. At present, Visual C++ 6's default opens in the center of the screen, leaving the remainder of the dialog box below the screen.

Would you please show me a way to do this?

Thanks in advance for your help,
Neil McCollum

Answer
Hello Neil.
I assume you are using MFC. You can position your dialog window using  CWnd::SetWindowPlacement in the dialog's OnInitDialog method.

Here is sample code

int screenWidth = GetSystemMetrics(SM_CXSCREEN); // Primary screen width
WINDOWPLACEMENT wp;
wp.length = sizeof(wp);
this->GetWindowPlacement(&wp);
int windowWidth = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
int windowHeight = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top;
wp.rcNormalPosition.top = 0;
wp.rcNormalPosition.bottom = wp.rcNormalPosition.top + windowHeight;
wp.rcNormalPosition.left = (screenWidth-windowWidth)/2;
wp.rcNormalPosition.right = wp.rcNormalPosition.left + windowWidth;
this->SetWindowPlacement(&wp);

I hope that helps you out.

Best regards
Zlatko

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Zlatko

Expertise

No longer taking questions.

Experience

No longer taking questions.

Education/Credentials
No longer taking questions.

©2012 About.com, a part of The New York Times Company. All rights reserved.