Effective screen resolution at high DPI settings ?

Started by Jean-pierre Leroy, April 11, 2013, 05:43:40 PM

Previous topic - Next topic

Jean-pierre Leroy

Dear all,

At a high DPI settings text and UI elements are rendering by using more pixels; This has the effect of lowering the screen real estate available to the application.

Is-there is a simple way to detect the effective screen resolution instead of the physical resolution ?

This is the C code published by Microsoft in this page :

http://msdn.microsoft.com/en-us/library/windows/desktop/dd464660%28v=vs.85%29.aspx#handling_minimum_effective_resolution


CDPI g_metrics;
// Make sure the effective resolution is high enough before continuing.
if (!g_metrics.IsResolutionAtLeast(800, 600))
{
   if (MessageBox(NULL,
   L"Effective screen resolution must be at least 800x600. It is recommended that you either increase your screen resolution setting or reduce your DPI scaling setting.  Continue?",
   L"Warning",
   MB_YESNO | MB_ICONWARNING)
   == IDNO)
   {
       return FALSE;
   }
}


And here is the function IsResolutionAtLeast()


// Determine if screen resolution meets minimum requirements in relative
    // pixels.
    bool IsResolutionAtLeast(int cxMin, int cyMin)
    {
        return (ScaledScreenWidth() >= cxMin) && (ScaledScreenHeight() >= cyMin);
    }


I searched in Jose Roca WinApiHeader, but I was not able to find an equivalent function.

Thanks for your help.
Jean-Pierre

José Roca

Add this function at the end of AfxWin.inc.



' ========================================================================================
' Determine if screen resolution meets minimum requirements in relative pixels.
' ========================================================================================
FUNCTION AfxIsResolutionAtLeast (BYVAL cxMin AS LONG, BYVAL cyMin AS LONG) AS LONG
   LOCAL dpiX, dpiY AS SINGLE
   AfxGetDesktopDPI(dpiX, dpiY)
   LOCAL ScaledScreenWidth AS LONG, ScaledScreenHeight AS LONG
   ScaledScreenWidth = MulDiv(GetSystemMetrics(%SM_CXSCREEN), 96, dpiX)
   ScaledScreenHeight = MulDiv(GetSystemMetrics(%SM_CYSCREEN), 96, dpiY)
   FUNCTION = ((ScaledScreenWidth => cxMin) AND (ScaledScreenHeight => cyMin))
END FUNCTION
' ========================================================================================


Jean-pierre Leroy

Thank you Jose.

It's exactly the function I was looking for.

Regards. Jean-Pierre.