Public Group

GetSystemMetrics() questions

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

Recommended Posts

So.. im reading this book called "Beginning game programming" (by michael morrison), and this code appear:


// Calculate the window size and position based upon the game size
int iWindowWidth = m_iWidth + GetSystemMetrics(SM_CXFIXEDFRAME) * 2,
iWindowHeight = m_iHeight + GetSystemMetrics(SM_CYFIXEDFRAME) * 2 +
GetSystemMetrics(SM_CYCAPTION);
int iXWindowPos = (GetSystemMetrics(SM_CXSCREEN) - iWindowWidth) / 2,
iYWindowPos = (GetSystemMetrics(SM_CYSCREEN) - iWindowHeight) / 2;


it seems that CXFIXEDFRAME is the width of some frame and CYFIXEDFRAME is the heigh. Also the rest of the parameters to GetSystemMetrics() i cant figure out, neither why he multiply/minus/divide/plus as he does. MSDN isnt helping very well, so im hoping that someone can (i know its alot to ask for..) explain what GetSystemMetrics() does, what the parameters is, and what they do. -Mads

Share on other sites
GetSystemMetrics() is a function that returns information about the sizes of various window components (In this case, the size of the frame). Windows can have different sizes depending on the user style.

However, this isn't a good way to do what you want. There's a function specifically for this, AdjustWindowRectEx.

Share on other sites
Mmm.. I actually find MSDN quite helpful, but OK..

GetSystemMetrics returns some value from the system, where the parameter describes which value you want. SM_CXFIXEDFRAME returns the width of the border that will be around a window that you can't resize. SM_CYCAPTION returns the height of the title bar above the window, SM_CYMENU returns the height of the menu bar.

So, the first two lines take the size of the inner region of the window (the part in which you draw) from m_iWidth and m_iHeight and calculate the size of the whole window, including menus, title bars, the works.

SM_C(X/Y)SCREEN gives the size of the desktop in pixels. By substracting the window size and dividing by two, you get the position where the left-upper corner of the window should be to center the window on the screen.

Hope this helps.

Share on other sites
The author is making sure the Client area is guarenteed to be a certain size. I.e. if you use CreateWindow and tell it to make the window width and height 800x600 for example, the Client area will actually be less then this to compensate for menus, caption and borders. This can really screw up your math if you think your viewing plane is 800x600 but it's actually only 786x592 or whatever.

He multiples some of the metrics by two because usually there's borders on both the left and right side, and top and botoom.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
18

• 13
• 10
• 12
• 10
• 13
• Forum Statistics

• Total Topics
632997
• Total Posts
3009801
• Who's Online (See full list)

There are no registered users currently online

×