Solved

How to Centre Dialog?

Posted on 1998-09-22
4
698 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

Problems using Powershell and Active Directory?

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

789 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