?
Solved

How to Centre Dialog?

Posted on 1998-09-22
4
Medium Priority
?
702 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 150 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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 pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

770 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