Question

Is there any way to poll the actual physical aspect ratio (or even the dimensions) of the display device (not the display mode resolution - the screen itself)? ...and would the method work correctly despite the correct driver being installed for the monitor? I'm looking for Win32 API calls that will work with all Win32 platforms.

Was it helpful?

Solution

This is the closest I could come up with, using GetDeviceCaps() to determine the aspect ratio of the device corresponding to the desktop DC. A snippet from my code...

    HDC hDC = GetDC(NULL);
    if (hDC != NULL)
    {
        float dw = (float)GetDeviceCaps(hDC, HORZSIZE);
        float dh = (float)GetDeviceCaps(hDC, VERTSIZE);
        ReleaseDC(NULL, hDC);
        
        // Equivalent of reducing a fraction
        if (dw > dh)
        {
            dw /= dh;
            dh = 1.0f;
        }
        else
        {
            dh /= dw;
            dw = 1.0f;
        }

        wcp.fAspectNumerator = dw;
        wcp.fAspectDenominator = dh;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top