• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 705
  • Last Modified:

How to Centre Dialog?

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
softyan
Asked:
softyan
  • 2
1 Solution
 
NorbertCommented:
Which parameters do you pass when you call CreateWindow ?
0
 
softyanAuthor Commented:
hWndMain = CreateWindow(classname, classname, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
NULL, NULL, hInstance, NULL);

0
 
NorbertCommented:
Did you try to use Real Coordinates insted of CW_USEDEFAULT ?
0
 
Answers2000Commented:
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

Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now