How to request hardware resolution NATIVE of the main monitor in Windows?

I need to find the β€œbest” or native resolution for the connected LCD monitor under Windows (which I will then install programmatically and know how to do it.) Let me reiterate that I do not need permission from the current Windows, nor do I have to worry about CRT / projectors .

I saw how it works with this program, so I know that this is possible, despite the skeptics: http://www.entechtaiwan.com/util/moninfo.shtm

It would be better to talk directly with the monitor and request EDID information. However, I saw that it is cached in the registry and will not have a problem with extracting it from HKLM \ SYSTEM \ CurrentControlSet \ Enum \ DISPLAY, but cannot figure out how to match the data with the current main monitor.

I found this program in C: http://www.tech-archive.net/Archive/Development/microsoft.public.development.device.drivers/2004-08/0294.html and a similar python program: http: // www .koders.com / python / fid7FCCE3C908F376DC62F06CAD9B11C6D7C1CFA78F.aspx

Unfortunately, I have a lot of problems converting the C program to python, since the corresponding code does not seem to be in the win32all modules. I would try to compile it, but did not have disk space for a large compiler and have not used C for many years. I am a bit out of my element with ctypes.

My plan B will use EnumDisplaySettings () to find the highest resolution value and set it to this. On the PC I tried, it gives the correct answers, but this can be problematic.

I would prefer a solution in python, but maybe someone could help me change the program in C to spit out the resolution and compile it. Thanks in advance.

Update:

I found a potential solution. Now I read WMI to find a monitor that is available (not offline), grab its PNP device identifier and read the EDID from the registry in the subkey with the identification value. Then I parse the data for bytes 38 and 39 and compute. Not very clean, but I get results. If this is a reasonable way to do this, I will close this question, thanks.

+6
c python windows resolution monitor
source share
1 answer

It was decided to abandon conversations directly with the monitor and instead parse the EDID information stored in the cache in the registry. This code is not perfect, but it works:

import win32api as api, win32con as con, pywintypes import win32com.client _objWMIService = win32com.client.Dispatch('WbemScripting.SWbemLocator') _objSWbemServices = _objWMIService.ConnectServer('.', 'root\\cimv2') wmiquery = _objSWbemServices.ExecQuery # get_regval(regkey) is simple registry reading function. def get_monitor_res(): dtd = 54 # start byte of detailed timing desc. try: # get PNP id to find EDID in registry for monitor in wmiquery('Select * from Win32_DesktopMonitor'): # http://msdn.microsoft.com/en-us/library/aa394122%28VS.85%29.aspx if monitor.Availability in (3, 7, 13, 14, 15, 16): # connected curres = (monitor.ScreenWidth, monitor.ScreenHeight) print 'DEBUG: Current monitor resolution from WMI: %s' % (curres,) regkey = ('HKLM\\SYSTEM\\CurrentControlSet\\Enum\\' + monitor.PNPDeviceID + '\\Device Parameters\\EDID') edid = get_regval(regkey) if edid: print 'DEBUG: EDID Version: %s.%s' % (edid[18], edid[19]) # upper nibble of byte x 2^8 combined with full byte hres = ((edid[dtd+4] >> 4) << 8) | edid[dtd+2] vres = ((edid[dtd+7] >> 4) << 8) | edid[dtd+5] print 'DEBUG: EDID DTD0: ' + str((hres, vres)) res = (hres, vres) break # give up on first success else: raise RuntimeError, 'EDID not found in registry' except (RuntimeError, Exception) as err: print 'ERROR: %s.' % err return res 
+2
source share

All Articles