Sign in to follow this  

GetSystemMetrics() questions

This topic is 3862 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

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);
  if (wndclass.lpszMenuName != NULL)
    iWindowHeight += GetSystemMetrics(SM_CYMENU);
  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 this post


Link to post
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.
For more information, see The MSDN

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

Share this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

This topic is 3862 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this