Solved

How to Centre Dialog?

Posted on 1998-09-22
4
696 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
Comment Utility
Which parameters do you pass when you call CreateWindow ?
0
 

Author Comment

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

0
 
LVL 3

Expert Comment

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

Accepted Solution

by:
Answers2000 earned 50 total points
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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 and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now