Resolving monitor name in Windows (w/D3D)
category: code [glöplog]
So I've been looking to get the monitor driver description name on screen instead of it's lousy device ID (\\.\DISPLAY1), which I get now..
This was my first hunch but as said, that doesn't give me what I'm looking for. Anyone who has pulled that string out of somewhere before? Otherwise I'll continue my manhunt.
Code:
// Get name.
D3DADAPTER_IDENTIFIER9 d3dID;
d3d9.Get().GetAdapterIdentifier(iAdapter, 0, &d3dID);
dispAd.name = d3dID.Description;
// Add monitor ID to display adapter name.
FIX_ME // Not happy with this yet!
HMONITOR hMonitor = d3d9.Get().GetAdapterMonitor(iAdapter);
MONITORINFOEXA monInfoEx;
monInfoEx.cbSize = sizeof(MONITORINFOEXA);
if (GetMonitorInfoA(hMonitor, &monInfoEx))
{
dispAd.name = dispAd.name + " on: " + monInfoEx.szDevice;
}
else TPB_ASSERT(0); // Mute?
This was my first hunch but as said, that doesn't give me what I'm looking for. Anyone who has pulled that string out of somewhere before? Otherwise I'll continue my manhunt.
have you tried debugging the monInfoEx structure? :)
Please post the answer if you find it. I'm sick and tired of having the lame device ID as the string in my config-dialog as well... ;)
OK, there's at least SOME relevant info here...
WMI is the way to go for most of the stuff you need...
Rasmus: I think I gave it a proper look back when I wrote this. Ill fix and post the answer. Thanks guys.
WMI is teh cancer but indeed has a lot of info can can't get any other way...
You can pass the device string from the MONITORINFOEX structure to EnumDisplayDevices() - that will give you more info. Sadly the friendly name member of the DISPLAY_DEVICE struct it fills out always reads "Plug and Play monitor" if no specific monitor driver is installed - as is the case on most computers. Doesn't help too much :(
Well kb your option is at least better than what I have now, but I'm gonna check if WMI is workable. If so I'll supply a neatly encapsulated function to do it.
I found it usually rather convenient to just append the current monitor desktop resolutions.
Gargaj: I used to have 4 monitors, 3 of which was using the same resolution. It might be useful for compo-organizers, but I doubt it's very common for regular users to have multiple monitors with a different resolution.
A standard CPP WMI (+ fallback a-la KB) query is coming up, that is if it works -- coding/testing it.
kusma: I wouldn't know, but then if you have two screens of the same resolution, common sense would dictate it's the same model as well, in which case monitor name won't help you much either, I suppose.
Gargaj: Good point. Yeah, the three of them were indeed of the same model (one was of a different revision, but I'm not sure if that would show). Perhaps something like using the monitor the dialog box itself is located on is a better visual clue to the user?
It's still a bit of a moot point if you have 1 display head running 4 identical monitors, I'll give you that. It is possible to determine if a monitor is active (i.e switched into a mode) and probably to check if it is primary, secondary, tertiary. I'll see how far I will take this.
Well, there's also the method the "Identify" button uses in Windows.
Elaborate...
plek: write the monitor number on each of them.
kb: It seems like I can't pull much more information from WMI either if no specific driver is installed. But there is lots of other info!
plek: you know, draw big fuckoff number on each monitor :D
kusma: Well I can't find much through Win32_DesktopMonitor or any of the underlying classes. Where would I get a monitor number? Still unclear to me..
yeah I've seen it but where the hell does that number come from ;)
second parameter of EnumDisplayDevices?
Sorry, didn't look at that function yet, first wrote the WMI stuff. Going into that now.
superplek: I'm sorry, I'm currently at work so I can't look at it. I'm busy recompiling Linux kernels and whatnot.