使用SetupApi获取LCD EDID信息

获取更多的显示信息,可以参考微软的MSDN网站。网址如下:

http://msdn.microsoft.com/en-us/library/dd692964%28v=vs.85%29.aspx


http://msdn.microsoft.com/en-us/library/windows/hardware/ff551069%28v=vs.85%29.aspx


#include "windows.h"
#include "setupapi.h"
#include "initguid.h"
#include "stdio.h"

#define NAME_SIZE 128
#define PRINT(_x_) printf _x_

DEFINE_GUID (GUID_CLASS_MONITOR, 0x4d36e96e, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18);


int EdidDecode(unsigned char *pEdid, DWORD size)
{
	char table[27]={'0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

	unsigned int *sn=(unsigned int*)&pEdid[0x0c];

	printf("\n\n====== EDID Decode======");
	printf("\nMonitor ID: %c%c%c%02X%02X", table[pEdid[0x08]>>2&0x1f], table[(pEdid[0x08]&0x3)<<3|pEdid[0x09]>>5], table[pEdid[0x09]&0x1f]
										, pEdid[0x0b],pEdid[0x0a]);
	printf("\nEDID Date: Week%d, Year%d", pEdid[0x10],pEdid[0x11]+1990);
	printf("\nEDID Version: %X.%X", pEdid[0x12],pEdid[0x13]);
	printf("\nSerial Number: %d", *sn);
	printf("\nMonitor Name: ");
	for(int i=0; i<15;i++)
		if(isprint(pEdid[0x6f+i]))
			printf("%c", pEdid[0x6f+i]);
	printf("\nEDID Checksum: 0x%02X", pEdid[0x7f]);

	return 1;
}


static void getDeviceInfo(IN HDEVINFO devInfo, IN PSP_DEVINFO_DATA devInfoData)
{
	HKEY hDevRegKey;
	DWORD uniID[123];
	unsigned char EDIDdata[1024];
	DWORD edidsize=sizeof(EDIDdata);

	if (SetupDiGetDeviceRegistryProperty(devInfo, devInfoData,
										SPDRP_DEVICEDESC,//SPDRP_UI_NUMBER,
										NULL,
										(PBYTE)(&uniID),
										sizeof(uniID),
										NULL))
	{
		//printf("UID: %s\n",uniID);
	}
	else {
		printf("ERROR: %d\n",GetLastError());
	}

	hDevRegKey = SetupDiOpenDevRegKey(devInfo, devInfoData,
									DICS_FLAG_GLOBAL,
									0,
									DIREG_DEV,
									KEY_ALL_ACCESS);

	if (hDevRegKey) {
		LONG retValue,i;
		DWORD dwType, AcutalValueNameLength= NAME_SIZE;

		CHAR valueName[NAME_SIZE];

		for (i = 0, retValue = ERROR_SUCCESS; retValue !=ERROR_NO_MORE_ITEMS; i++)
		{
			DWORD j;

			retValue = RegEnumValueA (hDevRegKey, i, &valueName[0], &AcutalValueNameLength, NULL, &dwType, EDIDdata, &edidsize); // buffer size
			if (retValue == ERROR_SUCCESS )
			{
				if (!strcmp(valueName,"EDID")) {
					printf("Found value EDID\n");
					
					for (j=0;j

你可能感兴趣的:(C/C++)