I am developing a VB application in which i need to know the native resolution of the monitor and not the one set by the user(current resolution). So i need to read the EDID
For some source code (although C/C++) to read the EDID block see Point 5 at this link. The only official means to retrieve this information through Windows Setup API.
For an EDID format description see for example here.
After a lot of research i was able to fix my problem.. Thanks for the the valuable info Yahia.
First, we need to find the EDID data . The physical display information is in fact available to the OS, via Extended Display Identification Data(EDID). A copy of the EDID block is kept in the windows registry. But the problem was to obtain the correct EDID, as the registry has information stored about all the monitors which have been, at any point of time, attached to the system. So, first we use a WMI class “Win32_DesktopMonitor”, and through a simple SQL query grab the PNP device id to find a monitor that is available (not offline). We can then dig into the registry to find the data.
`'for monitor in wmiquery('Select * from Win32_DesktopMonitor'):
regkey = ('HKLM\SYSTEM\CurrentControlSet\Enum\' + monitor.PNPDeviceID + '\Device Parameters\EDID') edid = get_regval(regkey)'`
Second, it is necessary to parse the data. The base EDID information of a display is conveyed within a 128-byte data structure that contains pertinent manufacturer and operation-related data. Most of this information is uninteresting to us.
To know the NATIVE resolution we need to start looking in the DTD ( Detailed timing descriptor ) which starts at byte = 54.
Following is the logic for finding the maximum resolution from the EDID
`dtd = 54 # start byte of detailed timing desc.
horizontalRes = ((edid[dtd+4] >> 4) << 8) | edid[dtd+2] verticalRes = ((edid[dtd+7] >> 4) << 8) | edid[dtd+5] res=(horizontalRes,verticalRes)`
The values obtained are Hex values which can be converted to Decimal to find the NATIVE RESOLUTION in pixels.
Thanks Hope it helps Sachin
'Here is a complete solution for everything except for actually setting the resolution. This will read out the native resolution settings from the EDID of the active monitor.
Set WshShell = WScript.CreateObject("WScript.Shell")
Const HKEY_LOCAL_MACHINE = &H80000002 Const DTD_INDEX = 54
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\cimv2") Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "\root\default:StdRegProv")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DesktopMonitor",,48)
For Each objItem in colItems 'Gets active monitor EDID registry path
strKeyPath = "SYSTEM\CurrentControlSet\Enum\" & objItem.PNPDeviceID & "\Device Parameters"
Next
oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,"EDID",arrRawEDID
hor_resolution = arrRawEDID(DTD_INDEX + 2) + (arrRawEDID(DTD_INDEX + 4) And 240) * 16 vert_resolution = arrRawEDID(DTD_INDEX + 5) + (arrRawEDID(DTD_INDEX + 7) And 240) * 16
WshShell.Run "res.exe " & hor_resolution & " " & vert_resolution