dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: Get Monitor Resolution

  1. #1
    Join Date
    Sep 2011
    Posts
    3

    Get Monitor Resolution

    Hi,

    I'm looking for a method to get the monitor resolution (native) or the current pixel aspect ratio.

    I want the resolution of the hardware LCD screen (number of pixels... width and height)... not the current resolution from windows panel

    If this info is not available, I would like to know the pixel aspect ratio (if not square). Why? Because when I run my direct3D app in fullscreen, the pixel aspect is not always square and I have an image not well stretched.

    This happens with a 1920x1080 monitor (native) and when I use 1600x900 resolution in full screen.

    Any idea to fix this bug?
    Thanks.

  2. #2
    Join Date
    Sep 2011
    Posts
    2

    Re: Get Monitor Resolution

    there u go:

    int width = GetSystemMetrics(SM_CXSCREEN);
    int height = GetSystemMetrics(SM_CYSCREEN);

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,148

    Re: Get Monitor Resolution

    Note that SM_CXSCREEN/SM_CYSCREEN give the width/height of the primary monitor.
    On a multi monitor system, you can use EnumDisplayMonitors or GetDeviceCaps.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  4. #4
    Join Date
    Sep 2011
    Posts
    3

    Re: Get Monitor Resolution

    no I don't want the resolution of the current display settings.

    I want to know the physical resolution of the monitor (hardware). I have a 24" with 1920x1080 pixels and I want to get 1920 for width and 1080 for height even if my current resolution under windows is 1024x576

  5. #5
    Join Date
    Apr 2009
    Posts
    598

    Re: Get Monitor Resolution

    Try EnumDisplaySettingsEx with ENUM_CURRENT_SETTINGS

    See also a previous discussion at http://www.codeguru.com/forum/showthread.php?t=348483

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,602

    Re: Get Monitor Resolution

    Quote Originally Posted by olivthill2 View Post
    Try EnumDisplaySettingsEx with ENUM_CURRENT_SETTINGS

    See also a previous discussion at http://www.codeguru.com/forum/showthread.php?t=348483
    This is not what the guy wants. He wants physical device resolution, while the proposed by you give logical resolution values.
    Best regards,
    Igor

  7. #7
    Join Date
    Sep 2011
    Posts
    3

    Re: Get Monitor Resolution

    I found a trick with DirectX to retrieve the physical resolution of the monitor

    Enumerate all available full screen resolutions with EnumAdapterModes, and the biggest resolution should be the physical resolution

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,602

    Re: Get Monitor Resolution

    and the biggest resolution should be the physical resolution
    No it shouldn't. It just depends on installed/selected video driver capabilities. In most likely 99% cases it's going to work as expected. But no guarantee for working always fine.
    Best regards,
    Igor

  9. #9
    Join Date
    Nov 2007
    Posts
    613

    Re: Get Monitor Resolution

    GetDeviceCaps

  10. #10
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,602

    Re: Get Monitor Resolution

    GetDeviceCaps
    Again, it gives logical resolution, not monitor device physical characteristics.
    Best regards,
    Igor

  11. #11
    Join Date
    Nov 2007
    Posts
    613

    Re: Get Monitor Resolution

    Quote Originally Posted by Igor Vartanov View Post
    Again, it gives logical resolution, not monitor device physical characteristics.
    The MSDN site is somehow confusing, take an excerpt from the MSDN that came with VS6:
    HORZRES Width, in pixels, of the screen.
    VERTRES Height, in raster lines, of the screen.
    This function targets PHYSICAL DEVICES.
    You should try it first.
    Last edited by srelu; September 17th, 2011 at 10:19 PM. Reason: incomplete

  12. #12
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,602

    Re: Get Monitor Resolution

    You should try it first.
    Already did.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)