I am making a call through interop to GetScaleFactorForMonitor() on a Windows8.1 Surface3 tablet. It responds with a scaling factor of 140. I only have one monitor on this tablet. I set the flag for this call to both nearest to window and primary display to see if any difference just for the hell of it and both give 140.
The issue is, the actual scaling is 150%. When I go to view display settings in Windows it says 1440x2160 but the native resolution is 960x1440 (which I got from calling Screen.PrimaryScreen.Bounds).
I also get 960x1440 when calling SystemInformation.PrimaryMonitorSize.Height and Width.
I explored another route trying to use GetDpiForMonitor(). My thinking is if I get the raw DPI and then the scaled DPI I could do a percentage calculation.
It sort of works but the value I get for the raw DPI seems to be the effective(scaled) DPI and visa versa. For effective DPI for both x and y I get 96 and for raw I get 144. I would expect the raw to be a lower number.
Here are my calls:
GetDpiForMonitor(MonitorFromWindow(myTextbox.TopLevelControl.Handle, MONITOR_DEFAULTTONEAREST),
MONITOR_DPI_TYPE.MDT_Effective_DPI,
out effectiveDPIx,
out effectiveDPIy);
GetDpiForMonitor(MonitorFromWindow(myTextbox.TopLevelControl.Handle, MONITOR_DEFAULTTONEAREST),
MONITOR_DPI_TYPE.MDT_Raw_DPI,
out rawDPIx,
out rawDPIy);
Here is the struct I am using that is a mirror of the one on MSDN.
public enum MONITOR_DPI_TYPE : int
{
MDT_Effective_DPI = 0,
MDT_Angular_DPI = 1,
MDT_Raw_DPI = 2,
MDT_Default = MDT_Effective_DPI
};
GetScaleFactorForMonitor
does not return the correct scaling factor. I can repro the exact behavior that you describe. When I have a 150% scale applied (144 DPI on the test monitor, compared to a 96 system DPI),GetScaleFactorForMonitor
returns 140. One would obviously expect it to return 150, since 144/96=1.5. As for your second question, I suspect it's related to the fact that you haven't included a manifest in your application that specifies you are per-monitor high DPI compatible. See: msdn.microsoft.com/en-us/library/windows/desktop/…GetScaleFactorForMonitor
is based on the Windows Store scaling modes, which are actually different than those for desktop applications. (See blogs.technet.microsoft.com/askcore/2015/12/08/…, in particular the section named "Unified and extended scaling system".) Your best bet is to useGetDpiForMonitor
. It's too bad the per-monitor scaling support is utterly broken, even in the latest version Windows 10. The Windows team is delivering nothing but disappointment these days.