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

Thread: Is there API to know screen ratio?

  1. #1
    Join Date
    Oct 2007
    Posts
    4

    Is there API to know screen ratio?

    Is there API or MFC function to know screen ratio(4:3, 16:10, 16:9)?
    Isthere API or MFC function to know if it is wide monitor or normal monitor?

    Thank you.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,555

    Re: Is there API to know screen ratio?

    GetSystemMetrics

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

    Re: Is there API to know screen ratio?

    Retrieve the width and height of the screen, divide them to get the aspect ratio.
    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
    Oct 2007
    Location
    Fredericksburg, VA
    Posts
    41

    Re: Is there API to know screen ratio?

    That'll only work if the screen is set to the proper resolution, it won't actually tell you the dimensions of the monitor itself?

    You need to use the monitors built-in interface, or the video card driver to do that I thought?

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,555

    Re: Is there API to know screen ratio?

    Quote Originally Posted by bderagon
    That'll only work if the screen is set to the proper resolution, it won't actually tell you the dimensions of the monitor itself?

    You need to use the monitors built-in interface, or the video card driver to do that I thought?
    He didn't ask for the monitor size, only the ratio.

  6. #6
    Join Date
    Oct 2007
    Location
    Fredericksburg, VA
    Posts
    41

    Re: Is there API to know screen ratio?

    Sorry, I responded too quick, he actually did request both.

  7. #7
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046

    Re: Is there API to know screen ratio?

    Hello,

    Best way may be to get the screen DC and use GetDeviceCaps to find the pixels (VERTRES, HORZRES) and pixels per inch (LOGPIXELSX, LOGPIXELSY) of X and Y direction. From these data, it is easy to calculate the aspect ratio.

    Better still, GetDeviceCaps, when called with parameter HORZSIZE / VERTSIZE returns the entire width / height of physical screen.

    Code:
    HDC hDC = ::GetDC(NULL);
    int nWidth = GetDeviceCaps(hDC, HORZSIZE);
    int nHeight = GetDeviceCaps(hDC, VERTSIZE);
    CString sRatio;
    sRatio.Format("Width to Height ratio is %d:%d", nWidth, nHeight);
    pDC->TextOut(0, 0, sRatio);
    ::ReleaseDC(NULL, hDC);
    Regards,
    Pravin.
    Let me know if I have helped by rating this post

    Recent FAQs

    Drag an image
    Area of a window exposed on desktop
    Display rotated bitmap

  8. #8
    Join Date
    Oct 2007
    Posts
    4

    Re: Is there API to know screen ratio?

    Unexpectedly, GetDeviceCaps returns value which depends on resolution.
    When I set resolution as 1920x1200 for my 24 inch wide monitor, it returns
    520 mm x 325 mm. This value is actual size of 24 inch wide monitor.
    But, when I set resolution as 1280x1024, it returns 412 mm x 330 mm.
    Is MSDN wrong?
    Is there any way to know physical size of monitor in mm or ratio, regardless of resolution?
    Last edited by tropicchs2; October 26th, 2007 at 02:40 PM.

  9. #9
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046

    Re: Is there API to know screen ratio?

    Hello,

    I have checked with various resolution settings. All the time, monitor aspect ratio was returned as 320:240. Are you sure that your monitor installation settings are correct?

    I must admit that I have checked with the code snippet I had earlier posted and not using (VERTRES, HORZRES) and (LOGPIXELSX, LOGPIXELSY). But that also can be easily checked. I do not feel that it will yield a different answer.

    Regards,
    Pravin.
    Let me know if I have helped by rating this post

    Recent FAQs

    Drag an image
    Area of a window exposed on desktop
    Display rotated bitmap

  10. #10
    Join Date
    Oct 2007
    Posts
    4

    Re: Is there API to know screen ratio?

    I used GetDeviceCaps(hDC, HORZSIZE) and I am sure it's return value depends on resolution.
    Anyway thank you. I decided to use different method.

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)