This topic is now archived and is closed to further replies.

Centering a window

This topic is 5014 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, How do I centering a window, which I created with CreateWindow()? It's my main window, not a child-window. Thx in advance. /quackie [edited by - quackie on March 26, 2004 5:52:48 AM]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Just use the GetSystemMetrics function to calculate the where the center of the screen is (ie in 1024 * 768 it is at x 512 and y 384 ) Then set the X position for the window like this:

int x_size = GetSystemMetrics(SM_CXSCREEN);
int y_size = GetSystemMetrics(SM_CYSCREEN);

then do a calc where to put your window:

int mywindowwidth = 800;
int mywindowheight = 600;

int xpos = x_size/2 - mywindowwidth/2;
int ypos = y_size/2 - mywindowheight/2;

I think that should do it... Or atleast that''s a hint on how to do it properly... Check out MSDN, it really helps yopu know..

Share this post

Link to post
Share on other sites