c语言中EDID拨码的函数不用到linux怎么写
时间: 2024-03-29 10:34:49 浏览: 103
EEPROM读写上位机 EDID读写上位机
如果不使用Linux系统的API,可以通过第三方库或者直接操作硬件接口实现在C语言中读取显示器的EDID信息。以下是一个使用Windows系统的API读取EDID信息的示例:
```c
#include <windows.h>
#include <stdio.h>
BOOL GetEDID(BYTE EDIDBuffer[128])
{
DISPLAY_DEVICE displayDevice;
DWORD deviceIndex = 0;
DWORD displayIndex = 0;
HDC displayHandle;
ZeroMemory(&displayDevice, sizeof(DISPLAY_DEVICE));
displayDevice.cb = sizeof(DISPLAY_DEVICE);
// Find the display device for each display
while (EnumDisplayDevices(NULL, deviceIndex, &displayDevice, 0))
{
if (displayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE)
{
ZeroMemory(&displayDevice, sizeof(DISPLAY_DEVICE));
displayDevice.cb = sizeof(DISPLAY_DEVICE);
while (EnumDisplayDevices(NULL, deviceIndex, &displayDevice, 0))
{
if (displayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE)
{
if (EnumDisplayDevices(displayDevice.DeviceName, displayIndex, &displayDevice, 0))
{
displayHandle = CreateDC(displayDevice.DeviceName, NULL, NULL, NULL);
if (displayHandle != NULL)
{
if (GetEDIDFromMonitor(displayHandle, EDIDBuffer))
{
return TRUE;
}
DeleteDC(displayHandle);
}
}
}
displayIndex++;
ZeroMemory(&displayDevice, sizeof(DISPLAY_DEVICE));
displayDevice.cb = sizeof(DISPLAY_DEVICE);
}
}
deviceIndex++;
displayIndex = 0;
ZeroMemory(&displayDevice, sizeof(DISPLAY_DEVICE));
displayDevice.cb = sizeof(DISPLAY_DEVICE);
}
return FALSE;
}
BOOL GetEDIDFromMonitor(HDC displayHandle, BYTE EDIDBuffer[128])
{
DISPLAY_DEVICE displayDevice;
ZeroMemory(&displayDevice, sizeof(DISPLAY_DEVICE));
displayDevice.cb = sizeof(DISPLAY_DEVICE);
if (EnumDisplayDevices(NULL, 0, &displayDevice, 0))
{
DISPLAY_DEVICE monitorDevice;
ZeroMemory(&monitorDevice, sizeof(DISPLAY_DEVICE));
monitorDevice.cb = sizeof(DISPLAY_DEVICE);
if (EnumDisplayDevices(displayDevice.DeviceName, 0, &monitorDevice, 0))
{
HMONITOR hMonitor = NULL;
MONITORINFOEX monitorInfo;
ZeroMemory(&monitorInfo, sizeof(MONITORINFOEX));
monitorInfo.cbSize = sizeof(MONITORINFOEX);
for (DWORD monitorIndex = 0; EnumDisplayDevices(displayDevice.DeviceName, monitorIndex, &monitorDevice, 0); monitorIndex++)
{
hMonitor = MonitorFromPoint(monitorInfo.rcMonitor.topLeft, MONITOR_DEFAULTTONEAREST);
if (hMonitor != NULL)
{
MONITORINFOEX monitorInfo;
ZeroMemory(&monitorInfo, sizeof(MONITORINFOEX));
monitorInfo.cbSize = sizeof(MONITORINFOEX);
if (GetMonitorInfo(hMonitor, &monitorInfo))
{
PHYSICAL_MONITOR physicalMonitor;
HANDLE physicalMonitorHandle;
if (GetPhysicalMonitorsFromHMONITOR(hMonitor, 1, &physicalMonitor))
{
physicalMonitorHandle = physicalMonitor.hPhysicalMonitor;
if (GetEDIDFromPhysicalMonitor(physicalMonitorHandle, EDIDBuffer))
{
DestroyPhysicalMonitor(physicalMonitorHandle);
return TRUE;
}
}
}
}
}
}
}
return FALSE;
}
BOOL GetEDIDFromPhysicalMonitor(HANDLE physicalMonitorHandle, BYTE EDIDBuffer[128])
{
DWORD numEDIDBytes = 0;
if (GetNumberOfPhysicalMonitorsFromHMONITOR(physicalMonitorHandle, &numEDIDBytes))
{
if (numEDIDBytes > 0)
{
BYTE* EDID = (BYTE*)malloc(numEDIDBytes * sizeof(BYTE));
if (EDID != NULL)
{
if (GetPhysicalMonitorsFromHMONITOR(physicalMonitorHandle, numEDIDBytes, EDID))
{
memcpy(EDIDBuffer, EDID, 128);
阅读全文