# re: 多屏编程之如何获取显卡信息判断是否为多屏 回复 更多评论
2010-04-20 23:17 by
void GetDisplayName()
{
HKEY keyServ = NULL;
HKEY keyEnum = NULL;
HKEY key = NULL;
HKEY key2 = NULL;
DWORD error = 0;
LPCTSTR api = NULL;
DWORD type, count, size, i, iServ;
std::list <string> save;
setlocale (LC_ALL, ".ACP");
error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("SYSTEM\\CurrentControlSet\\Services"), 0, KEY_READ,&keyServ);
error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("SYSTEM\\CurrentControlSet\\Enum"),0,KEY_READ,&keyEnum);
i = 0;
for( iServ=0; ; ++iServ )
{
TCHAR name [0x200];
size = 0x200;
error = RegEnumKeyEx(keyServ, iServ,name,&size,NULL, NULL, NULL, NULL);
if(error == ERROR_NO_MORE_ITEMS)
break;
error = RegOpenKeyEx(keyServ, name, 0, KEY_READ, &key);
size = 0x200;
error = RegQueryValueEx(key, TEXT("Group"), 0, &type, (LPBYTE)name, &size);
if(error == ERROR_FILE_NOT_FOUND)
{ //键不存在
RegCloseKey (key);
continue;
};
if (_tcscmp (TEXT ("Video"), name) != 0)
{ // 不是显卡的内核驱动
RegCloseKey (key);
continue;
};
error = RegOpenKeyEx (key, TEXT ("Enum"),
0, KEY_READ, &key2);
RegCloseKey (key);
key = key2;
size = sizeof (count);
error = RegQueryValueEx (key, TEXT ("Count"),
0, &type, (LPBYTE)&count, &size);
for ( i=0; i < count; ++i )
{
TCHAR sz [0x200];
TCHAR name [0x40];
wsprintf (name, TEXT ("%d"), i);
size = sizeof (sz);
error = RegQueryValueEx (key, name,
0, &type, (LPBYTE)sz, &size);
error = RegOpenKeyEx (keyEnum, sz,
0, KEY_READ, &key2);
size = sizeof (sz);
error = RegQueryValueEx (key2, TEXT ("FriendlyName"),
0, &type, (LPBYTE)sz, &size);
if(error == ERROR_FILE_NOT_FOUND)
{
size = sizeof (sz);
error = RegQueryValueEx (key2, TEXT ("DeviceDesc"),
0, &type, (LPBYTE)sz, &size);
}
save.push_back (sz);
RegCloseKey (key2);
key2 = NULL;
}
RegCloseKey (key);
key = NULL;
}
RegCloseKey (keyEnum);
RegCloseKey (keyServ);
}