奇奇的空间

奇奇的空间
posts - 5, comments - 13, trackbacks - 0, articles - 23

多屏编程之如何获取显卡信息判断是否为多屏

Posted on 2006-11-27 16:18 奇奇 阅读(2135) 评论(1)  编辑 收藏 引用 所属分类: VC++

在stdafx.h
中加入:
#undef WINVER
#define WINVER 0x0500

*************************************************************

#ifndef SM_CMONITORS

typedef HANDLE HMONITOR;

#endif
#ifndef DISPLAY_DEVICE_PRIMARY_DEVICE

typedef struct _DISPLAY_DEVICE {
DWORD cb;
TCHAR DeviceName[32];
TCHAR DeviceString[128];
DWORD StateFlags;
} DISPLAY_DEVICE, *PDISPLAY_DEVICE, *LPDISPLAY_DEVICE;
#define DISPLAY_DEVICE_ATTACHED_TO_DESKTOP 0x00000001
#define DISPLAY_DEVICE_MULTI_DRIVER 0x00000002
#define DISPLAY_DEVICE_PRIMARY_DEVICE 0x00000004
#define DISPLAY_DEVICE_VGA 0x00000010

#endif

typedef BOOL (WINAPI* pEnumDisplayDevices)(PVOID,DWORD,PVOID,DWORD);
typedef BOOL (WINAPI* pEnumDisplaySettings)(PVOID,DWORD,PVOID);

pEnumDisplayDevices pStartEnumDisplayDevices;
pEnumDisplaySettings pStartEnumDisplaySettings;


*********************************************************************


int iCount;

pStartEnumDisplayDevices = (pEnumDisplayDevices)GetProcAddress(LoadLibrary("USER32"), "EnumDisplayDevicesA");
pStartEnumDisplaySettings = (pEnumDisplaySettings)GetProcAddress(LoadLibrary("USER32"), "EnumDisplaySettingsA");


if (pStartEnumDisplayDevices && pStartEnumDisplaySettings)
{
DISPLAY_DEVICE dd;
DEVMODE dv;

ZeroMemory(&dv, sizeof(dv));
ZeroMemory(&dd, sizeof(dd));

dv.dmSize = sizeof(dv);
dd.cb = sizeof(dd);

for (iCount=0; (*pStartEnumDisplayDevices)(NULL, iCount, &dd, 0); iCount++)
{
(*pStartEnumDisplaySettings)(dd.DeviceName,ENUM_CURRENT_SETTINGS,&dv);
if((dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
&&(dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE))
{
CString strDispName,strScreen,strColor,strFreq;

strDispName.Format(_T("Device Name: %s "),dd.DeviceString);
SetDlgItemText(IDC_STATIC_DISP_NAME,strDispName);

strScreen.Format(_T("%d×%d "),dv.dmPelsWidth,dv.dmPelsHeight);
SetDlgItemText(IDC_STATIC_FREQ,strScreen);

strColor.Format(_T("%d Bit"),dv.dmBitsPerPel);
SetDlgItemText(IDC_STATIC_COLOR,strColor);

strFreq.Format(_T("%d Hz"),dv.dmDisplayFrequency);
SetDlgItemText(IDC_STATIC_REFRESH_FREQ,strFreq);
}
}
}

Feedback

# re: 多屏编程之如何获取显卡信息判断是否为多屏  回复  更多评论   

2010-04-20 23:17 by wert
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);
}

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理