stitch2802
asked on
Monitor information using EnumDisplayDevices
Hi,
I'm trying to get the name of my monitor using the following code - it's giving me the name of the adapter instead:
bool MonitorInfo::Acquire()
{
TCHAR msg[10000] = {0};
DISPLAY_DEVICE dd;
dd.cb = sizeof(dd);
DWORD dev = 0; //device index
int id = 1; //monitor number as used by Display Properties -> Settings
while(EnumDisplayDevices(0 , dev, &dd, 0))
{
if(!(dd.StateFlags & DISPLAY_DEVICE_MIRRORING_D RIVER))
{
DISPLAY_DEVICE ddMon;
ZeroMemory(&ddMon, sizeof(ddMon));
ddMon.cb = sizeof(&ddMon);
DWORD devMon = 0;
while(EnumDisplayDevices(d d.DeviceNa me, devMon, &ddMon, 0))
{
if(ddMon.StateFlags & DISPLAY_DEVICE_ACTIVE)
break;
devMon++;
}
if(!*ddMon.DeviceString)
{
EnumDisplayDevices(dd.Devi ceName, 0, &ddMon, 0);
if(!*ddMon.DeviceString)
{
HRESULT hr = StringCchCopy(dd.DeviceStr ing, sizeof(dd.DeviceString), TEXT("Default Monitor"));
if (FAILED(hr))
{
return false;
}
}
}
//get information about the display position and the current display mode
DEVMODE dm;
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm);
if(EnumDisplaySettingsEx(d d.DeviceNa me, ENUM_CURRENT_SETTINGS, &dm, 0) == FALSE)
{
EnumDisplaySettingsEx(dd.D eviceName, ENUM_REGISTRY_SETTINGS, &dm, 0);
}
//format information about this monitor
MonitorInfoEx monInfoEx;
HRESULT hr = StringCchPrintf(monInfoEx. refreshRat e, sizeof(monInfoEx.refreshRa te), TEXT("%d"), dm.dmDisplayFrequency);
if (FAILED(hr))
{
return false;
}
//device name
hr = StringCchCopy(monInfoEx.na me, sizeof(monInfoEx.name), ddMon.DeviceString);
if (FAILED(hr))
{
return false;
}
id++;
monitors.push_back(monInfo Ex);
}
dev++;
}
return true;
}
I've tried different combinations in the EnumDisplayDevices, but it either gives me the name of the video card or "Default Monitor". What I want is the name of the monitor as stated in the Device Manager.
Help, please?
TIA,
S/.
I'm trying to get the name of my monitor using the following code - it's giving me the name of the adapter instead:
bool MonitorInfo::Acquire()
{
TCHAR msg[10000] = {0};
DISPLAY_DEVICE dd;
dd.cb = sizeof(dd);
DWORD dev = 0; //device index
int id = 1; //monitor number as used by Display Properties -> Settings
while(EnumDisplayDevices(0
{
if(!(dd.StateFlags & DISPLAY_DEVICE_MIRRORING_D
{
DISPLAY_DEVICE ddMon;
ZeroMemory(&ddMon, sizeof(ddMon));
ddMon.cb = sizeof(&ddMon);
DWORD devMon = 0;
while(EnumDisplayDevices(d
{
if(ddMon.StateFlags & DISPLAY_DEVICE_ACTIVE)
break;
devMon++;
}
if(!*ddMon.DeviceString)
{
EnumDisplayDevices(dd.Devi
if(!*ddMon.DeviceString)
{
HRESULT hr = StringCchCopy(dd.DeviceStr
if (FAILED(hr))
{
return false;
}
}
}
//get information about the display position and the current display mode
DEVMODE dm;
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm);
if(EnumDisplaySettingsEx(d
{
EnumDisplaySettingsEx(dd.D
}
//format information about this monitor
MonitorInfoEx monInfoEx;
HRESULT hr = StringCchPrintf(monInfoEx.
if (FAILED(hr))
{
return false;
}
//device name
hr = StringCchCopy(monInfoEx.na
if (FAILED(hr))
{
return false;
}
id++;
monitors.push_back(monInfo
}
dev++;
}
return true;
}
I've tried different combinations in the EnumDisplayDevices, but it either gives me the name of the video card or "Default Monitor". What I want is the name of the monitor as stated in the Device Manager.
Help, please?
TIA,
S/.
EnumDisplayDevices should return the name of the display card (instead of the monitor). What about EnumDisplayMonitors and GetMonitorInfo function with MONITORINFOEX?
ASKER
Could you give me an example, please?
ASKER
Thanks, but that isn't what I'm looking for - the combination of EnumDisplayMonitors and GetMonitorInfo, along with MONITORINFOEX gives me the following output: \\.\Display1
I'm trying to get the name of the monitor, for example: Samsung SyncMaster 753 DF.
TIA,
s/.
I'm trying to get the name of the monitor, for example: Samsung SyncMaster 753 DF.
TIA,
s/.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
rhanneken,
You're a genius! =)
Exactly what I was looking for, thanks!
s/.
You're a genius! =)
Exactly what I was looking for, thanks!
s/.