Solved

How to Centre Dialog?

Posted on 1998-09-22
4
697 Views
Last Modified: 2008-02-01
I don't know why when i used CreateWindow to create a dialog, it always shows on the upper left conner of the screen. How can i show it on the center of screen?
0
Comment
Question by:softyan
  • 2
4 Comments
 
LVL 3

Expert Comment

by:Norbert
ID: 1252979
Which parameters do you pass when you call CreateWindow ?
0
 

Author Comment

by:softyan
ID: 1252980
hWndMain = CreateWindow(classname, classname, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
NULL, NULL, hInstance, NULL);

0
 
LVL 3

Expert Comment

by:Norbert
ID: 1252981
Did you try to use Real Coordinates insted of CW_USEDEFAULT ?
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1252982
CW_USEDEFAULT means windows decides where to put it (and it makes some funny choices).

Therefore give your own coordinates to center the window :


int nScreenWidth = GetSystemMetrics( SM_CXSCREEN ) ;
int nScreenHeight = GetSystemMetrics( SM_CYSCREEN ) ;

/*
 say nWidth and nHeight are the size you require for the window
 if you want to calculate them you could say pick 1/2 or 3/4
 of the screen size, or else hard code a size
*/
int nWidth = some_value ;
int nHeight = some_value ;

int xx = ( nScreenWidth - nWidth ) / 2 ;
int yy = ( nScreenHeight - nHeight ) / 2 ;

/* xx and yy now contain the x,y pos for the window */

/* Now call create window with xx, yy for x,y pos and nWidth, nHeight for width & height */
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

774 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question