Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the name of a monitor

Tags:

c++

winapi

I'm having a bit of trouble retrieving the name of a monitor with winapi. According to other entries on stackoverflow, the correct way to get the name of a monitor is this:

EnumDisplayDevices(nullptr, 0, &oDisplayDevice, 0);

char lpszDeviceName[32];
memcpy(lpszDeviceName, oDisplayDevice.DeviceName, 32);

EnumDisplayDevices(lpszDeviceName, 0, &oDisplayDevice, 0);

char lpszMonitorName[128];
memcpy(lpszMonitorName, oDisplayDevice.DeviceString, 128);

However, EnumDisplayDevices returns FALSE the second time around. The first time around, DeviceName is \\DISPLAY1 and DeviceString is the GPU vendor. Using the MONITORINFOEX struct gives me the same value as DeviceName.

To be clear I'm looking for something like "Samsung blah blah," or what appears in the control panel on the screen resolution page.

like image 208
NmdMystery Avatar asked Nov 19 '13 00:11

NmdMystery


People also ask

What is the name of monitor screen?

The display in modern monitors is typically an LCD with LED backlight, having by the 2010s replaced CCFL backlit LCDs. Before the mid-2000s, most monitors used a CRT. Monitors are connected to the computer via DisplayPort, HDMI, USB-C, DVI, VGA, or other proprietary connectors and signals.

How do I find the display name of my laptop?

Click Start, right-click Computer, and then click Properties. The computer name appears under Computer name, domain, and workgroup settings.

How do I find my Dell monitor model?

The label is hidden on a card that tucks in on the left side of the monitor above the USB interface ports (Figure 1). The serial number, Service Tag (if applicable), and model number information will be located on the front of the card.


1 Answers

This seems to return the proper data for me:

#include <Windows.h>
#include <iostream>
#include <string>

int main()
{
    DISPLAY_DEVICE dd;
    dd.cb = sizeof(dd);
    int deviceIndex = 0;
    while(EnumDisplayDevices(0, deviceIndex, &dd, 0))
    {
        std::string deviceName = dd.DeviceName;
        int monitorIndex = 0;
        while(EnumDisplayDevices(deviceName.c_str(), monitorIndex, &dd, 0))
        {
            std::cout << dd.DeviceName << ", " << dd.DeviceString << "\n";
            ++monitorIndex;
        }
        ++deviceIndex;
    }
    return 0;
}

If you're compiling for UNICODE then use this instead:

#include <Windows.h>
#include <iostream>
#include <string>

int main()
{
    DISPLAY_DEVICE dd;
    dd.cb = sizeof(dd);
    int deviceIndex = 0;
    while(EnumDisplayDevices(0, deviceIndex, &dd, 0))
    {
        std::wstring deviceName = dd.DeviceName;
        int monitorIndex = 0;
        while(EnumDisplayDevices(deviceName.c_str(), monitorIndex, &dd, 0))
        {
            std::wcout << dd.DeviceName << L", " << dd.DeviceString << L"\n";
            ++monitorIndex;
        }
        ++deviceIndex;
    }
    return 0;
}

Here's an example of the output:

\.\DISPLAY1\Monitor0, Dell U2410(DP)
\.\DISPLAY2\Monitor0, Dell 2407WFP-HC (Digital)

like image 171
Retired Ninja Avatar answered Oct 21 '22 12:10

Retired Ninja