locked
why GetSystemMetrics(SM_CXSCREEN) returns 1280 on surface pro instead of 1920?

    Question

  • Hi buddies,

    on surface pro, screen resolution set to 1920x1080, now calling:

        gScreenWidth = GetSystemMetrics(SM_CXSCREEN);
        gScreenHeight = GetSystemMetrics(SM_CYSCREEN);

    would get:

    gScreenWidth=1280 and gScreenHeight=720

    why not 1920x1080?

    can anybody kindly give me an answer?

    thanks,

    nunu

    

    Sunday, April 28, 2013 2:54 PM

Answers

  • 1280 * 1.5 == 1920.

    1.5 is one of the common display scaling settings for the surface pro. So maybe it is reporting 'Device Independent Pixels' (DIP)s rather than physical pixels. You can set the project to be 'DPI aware' so it will ignore the 1.5 factor.... if this is actually what your problem that is.

     http://msdn.microsoft.com/en-us/library/windows/desktop/ff684173(v=vs.85).aspx  about halfway down it tells you how to make your project DPI aware.


    Unlock The *I don't use 3 angles in a Vector3 for rotations anymore* Achievement Here


    • Edited by Shazen Sunday, April 28, 2013 4:37 PM
    • Marked as answer by gnunu Tuesday, April 30, 2013 4:08 PM
    Sunday, April 28, 2013 4:34 PM
  • You aren't adjusting for the system's dpi. Since you posted this in Windows Store C++, I'll assume that you're actually using this is a Windows Store app. Given that assumption, you should be doing something like:

    auto dpiAdjust = Windows::Graphics::Display::DisplayProperties::LogicalDpi / 96.0F;
    
    float screenWidth = GetSystemMetrics(SM_CXSCREEN) * dpiAdjust;
    float screenHeight = GetSystemMetrics(SM_CYSCREEN) * dpiAdjust;
    

    with the appropriate static_cast conversion from screenWidth to gScreenWidth and screenHeight to gScreenHeight.

    If this is Win32 programming and you posted this question in the wrong forum, this link explain high-dpi awareness and includes sample code for how to properly adjust for system dpi: http://msdn.microsoft.com/en-us/library/windows/desktop/dd464660(v=vs.85).aspx .


    Visual C++ MVP | Website | Blog | @mikebmcl | Windows Store DirectX Game Template

    • Marked as answer by gnunu Tuesday, April 30, 2013 3:02 PM
    Sunday, April 28, 2013 6:54 PM

All replies

  • 1280 * 1.5 == 1920.

    1.5 is one of the common display scaling settings for the surface pro. So maybe it is reporting 'Device Independent Pixels' (DIP)s rather than physical pixels. You can set the project to be 'DPI aware' so it will ignore the 1.5 factor.... if this is actually what your problem that is.

     http://msdn.microsoft.com/en-us/library/windows/desktop/ff684173(v=vs.85).aspx  about halfway down it tells you how to make your project DPI aware.


    Unlock The *I don't use 3 angles in a Vector3 for rotations anymore* Achievement Here


    • Edited by Shazen Sunday, April 28, 2013 4:37 PM
    • Marked as answer by gnunu Tuesday, April 30, 2013 4:08 PM
    Sunday, April 28, 2013 4:34 PM
  • You aren't adjusting for the system's dpi. Since you posted this in Windows Store C++, I'll assume that you're actually using this is a Windows Store app. Given that assumption, you should be doing something like:

    auto dpiAdjust = Windows::Graphics::Display::DisplayProperties::LogicalDpi / 96.0F;
    
    float screenWidth = GetSystemMetrics(SM_CXSCREEN) * dpiAdjust;
    float screenHeight = GetSystemMetrics(SM_CYSCREEN) * dpiAdjust;
    

    with the appropriate static_cast conversion from screenWidth to gScreenWidth and screenHeight to gScreenHeight.

    If this is Win32 programming and you posted this question in the wrong forum, this link explain high-dpi awareness and includes sample code for how to properly adjust for system dpi: http://msdn.microsoft.com/en-us/library/windows/desktop/dd464660(v=vs.85).aspx .


    Visual C++ MVP | Website | Blog | @mikebmcl | Windows Store DirectX Game Template

    • Marked as answer by gnunu Tuesday, April 30, 2013 3:02 PM
    Sunday, April 28, 2013 6:54 PM
  • Hi Mike,

    Thanks for the exact answer.

    Actually for now I am writing the win32 part of an app, so this should be the wrong place, sorry. But I think your answer is helpful in general. :-)

    Thanks again!

    Tuesday, April 30, 2013 3:14 PM
  • Hi Shazen,

    you also give the right answer, thanks!

    Tuesday, April 30, 2013 4:10 PM
  • For Windows Store apps see  Guidelines for scaling to pixel density . You can test how your app will run in different resolutions and scalings by using the simulator (see Change the simulated screen size and resolution)

    --Rob

    Tuesday, April 30, 2013 4:29 PM
    Owner