1

I'm using this bit of code to get a print out of the monitor resolution from a Surface Pro 1st Gen Win 8.1 PC using Python 2.7:

   import ctypes
   from ctypes import windll
   user32 = ctypes.windll.user32
   screensize = (user32.GetSystemMetrics(0), user32.GetSystemMetrics(1))
   print "Screensize:", screensize

But the problem is that I get different results based on running it through command prompt versus running the script through the Python shell.

Just running the script I get 1280x720, but through the IDLE Shell I get 1920x1080.

Now, since I'm running this on a Surface Pro, I'm almost certain that this has something to do with DPI scaling (someone brought up a similar problem here). If this is the case, then it must be because DPI scaling has been disabled for Python IDLE.

So how do I prevent this from happening so that I get consistent and accurate results when I run this code, regardless of how it's run or what kind of machine is running it or whether DPI scaling has been disabled or not? Maybe CEF Python?

Any help is much appreciated. Thank you.

Community
  • 1
  • 1
Benji A.
  • 142
  • 1
  • 14
  • You are indeed having issues with [DPI virtualization](https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266(v=vs.85).aspx) To make apps DPI aware they either have to include proper manifest file or call [SetProcessDpiAwareness](https://msdn.microsoft.com/en-gb/library/windows/desktop/dn302216.aspx) function before any Win API call that would trigger virtualization. I don't know how to do that for Python script... – Dalija Prasnikar May 21 '15 at 17:53
  • BTW, you are getting wrong (virtualized) numbers when you just run script and correct numbers from Python IDLE because Python IDLE **IS Dpi aware** and so your script launched through it will be too. – Dalija Prasnikar May 21 '15 at 17:57
  • Take a look at this [answer](http://stackoverflow.com/a/26539115/4267244) – Dalija Prasnikar May 21 '15 at 18:09

1 Answers1

0

If you want monitor info, call GetMonitorInfo.

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380