For one of my application (write in WPF), I need to get some informations about monitors : Current resolution, scaling factor and real resolution.
I know this question has been asked many times but I'm not able to find a good answer in all SO questions that talked about that...
In my case for example, I have 3 monitors placed in this order :
- Monitor 1 (integrated laptop screen) : 1920x1080, scaled at 125%
- Monitor 2 (LG 22") : 1920x1080, scaled at 100% (PRIMARY MONITOR)
- Monitor 3 (LG 22") : 1920x1080, scaled at 100%
When using System.Windows.Forms.Screen.AllScreens, I obtain a resolution of 1536x864 for my first monitor. It's OK because 1536*1.25 = 1920. But i'm not able to find either the 1.25 or the 1920 ^^
(for the other monitors it's OK because they're scaled at 100%).
But if I set monitor 1 to be primary I can obtain it's real resolution but for monitor 2 and 3 I obtain 2400*1350... It's 1920x1080 multiply by the primary monitor's scaling factor : 1.25
It's been 2 days since I try many ways. I've tried AllScreens in Windows.Forms. In WinAPI I've tried EnumDisplayMonitors, GetDeviceCaps, GetScaleFactorForMonitor, GetDpiForMonitor...
Everything always give me a 100% scaling factor or a DPI of 96 for my first monitor which is an error...
Do you know a secure way to obtain these informations ? In WMI, in registry, etc...
Thanks for your help !
(PS : if needed I can provide code sample of what I tried but I don't want to flood this first post)
EDIT : I forgot to mention that I need to obtain these informations without any visual app (my DLL is called from a VB application)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…