Git Product home page Git Product logo

Comments (2)

a1ive avatar a1ive commented on September 20, 2024
struct MATCH_DISPLAY_CTX
{
	LPCWSTR name;
	HMONITOR hm;
};

static BOOL MatchDisplayName(HMONITOR hMonitor, HDC hDC, LPRECT lpRect, LPARAM lParam)
{
	struct MATCH_DISPLAY_CTX* ctx = (struct MATCH_DISPLAY_CTX*)lParam;
	MONITORINFOEXW info = { .cbSize = sizeof(MONITORINFOEXW) };
	if (GetMonitorInfoW(hMonitor, (LPMONITORINFO)&info))
	{
		if (wcscmp(ctx->name, info.szDevice) == 0)
		{
			ctx->hm = hMonitor;
			return FALSE;
		}
	}
	return TRUE;
}

HMONITOR
NWL_GetMonitorHandleByHwID(LPCWSTR hwId)
{
	DWORD i, j;
	int len;
	WCHAR displayId[32];
	DISPLAY_DEVICEW displayDevice = { .cb = sizeof(DISPLAY_DEVICEW) };
	// MONITOR\XXXXXXX
	if (wcsncmp(hwId, L"MONITOR\\", 8) != 0)
		return NULL;
	len = swprintf(displayId, 32, L"\\\\?\\DISPLAY#%s#", &hwId[8]);
	if (len <= 0)
		return NULL;
	for (i = 0; EnumDisplayDevicesW(NULL, i, &displayDevice, EDD_GET_DEVICE_INTERFACE_NAME); i++)
	{
		DISPLAY_DEVICEW monitorDevice = { .cb = sizeof(DISPLAY_DEVICEW) };
		for (j = 0; EnumDisplayDevicesW(displayDevice.DeviceName, j, &monitorDevice, EDD_GET_DEVICE_INTERFACE_NAME); j++)
		{
			//MonitorDevice.DeviceID
			if (wcsncmp(monitorDevice.DeviceID, displayId, (size_t)len) == 0)
			{
				struct MATCH_DISPLAY_CTX ctx = { .name = displayDevice.DeviceName, .hm = NULL };
				EnumDisplayMonitors(NULL, NULL, MatchDisplayName, (LPARAM) &ctx);
				return ctx.hm;
			}
		}
	}
	return NULL;
}

from nwinfo.

a1ive avatar a1ive commented on September 20, 2024
void nwinfo_display(void)
{
	DWORD iDevNum = 0;
	DEVMODEA DevMode = { .dmSize = sizeof(DEVMODEA) };
	DISPLAY_DEVICEA DisplayDevice = { .cb = sizeof(DISPLAY_DEVICEA) };

	while (EnumDisplayDevicesA(NULL, iDevNum, &DisplayDevice, EDD_GET_DEVICE_INTERFACE_NAME))
	{
		DWORD State = DisplayDevice.StateFlags;
		printf("%s\n", DisplayDevice.DeviceName);
		printf("  %s\n", DisplayDevice.DeviceString);
		printf("  Device state: %s%s%s%s%s%s\n",
			(State & DISPLAY_DEVICE_ACTIVE) ? "active" : "deactive",
			(State & DISPLAY_DEVICE_MIRRORING_DRIVER) ? " mirroring" : "",
			(State & DISPLAY_DEVICE_MODESPRUNED) ? " modespruned" : "",
			(State & DISPLAY_DEVICE_PRIMARY_DEVICE) ? " primary" : "",
			(State & DISPLAY_DEVICE_REMOVABLE) ? " removable" : "",
			(State & DISPLAY_DEVICE_VGA_COMPATIBLE) ? " vga" : "");
		if (EnumDisplaySettingsExA(DisplayDevice.DeviceName, ENUM_CURRENT_SETTINGS, &DevMode, 0))
		{
			printf("  Current mode: %ux%u, %u Hz\n", DevMode.dmPelsWidth, DevMode.dmPelsHeight, DevMode.dmDisplayFrequency);
		}
		iDevNum++;
	}
}

from nwinfo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.