std::list<string> g_listVideoCard;
#define CHECK_ERROR(apiname) if(error != ERROR_SUCCESS){api=TEXT(apiname);goto failed;}
int GetVideoCardInfo()
{
HKEY keyServ = NULL;
HKEY keyEnum = NULL;
HKEY key = NULL;
HKEY key2 = NULL;
DWORD error = 0;
LPCTSTR api = NULL;
DWORD type, count, size, i, iServ;
setlocale (LC_ALL, ".ACP");
error = RegOpenKeyEx (HKEY_LOCAL_MACHINE, TEXT ("SYSTEM//CurrentControlSet//Services"),
0, KEY_READ, &keyServ);
CHECK_ERROR ("RegOpenKeyEx");
error = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
TEXT ("SYSTEM//CurrentControlSet//Enum"),
0, KEY_READ, &keyEnum);
CHECK_ERROR ("RegOpenKeyEx");
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;
CHECK_ERROR ("RegEnumKeyEx");
error = RegOpenKeyEx (keyServ, name, 0, KEY_READ, &key);
CHECK_ERROR ("RegOpenKeyEx");
size = 0x200;
error = RegQueryValueEx (key, TEXT ("Group"), 0, &type, (LPBYTE)name, &size);
if (error == ERROR_FILE_NOT_FOUND)
{ // 键不存在
RegCloseKey (key);
continue;
};
CHECK_ERROR ("RegQueryValueEx");
if (_tcscmp (TEXT ("Video"), name) != 0)
{ // 不是显卡的内核驱动
RegCloseKey (key);
continue;
};
error = RegOpenKeyEx (key, TEXT ("Enum"), 0, KEY_READ, &key2);
CHECK_ERROR ("RegOpenKeyEx");
RegCloseKey (key);
key = key2;
size = sizeof (count);
error = RegQueryValueEx (key, TEXT ("Count"), 0, &type, (LPBYTE)&count, &size);
CHECK_ERROR ("RegQueryValueEx");
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);
CHECK_ERROR ("RegQueryValueEx");
error = RegOpenKeyEx (keyEnum, sz,
0, KEY_READ, &key2);
CHECK_ERROR ("RegOpenKeyEx");
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);
};
CHECK_ERROR ("RegQueryValueEx");
g_listVideoCard.push_back (sz);
RegCloseKey (key2);
key2 = NULL;
};
RegCloseKey (key);
key = NULL;
};
RegCloseKey (keyEnum);
RegCloseKey (keyServ);
return 0;
failed:
if (keyServ)
RegCloseKey (keyServ);
if (keyEnum)
RegCloseKey (keyEnum);
if (key)
RegCloseKey (key);
if (key2)
RegCloseKey (key2);
return error;
};
/*
//获得C盘可用空间
DWORD sector,byte,cluster,free;
long int freespace,totalspace;
GetDiskFreeSpace(“C:”,&sector,&byte,&free,&cluster); //获得返回参数
totalspace=int(cluster)*int(byte)*int(sector)/1024/1024; //计算总容量
freespace=int(free)*int(byte)*int(sector)/1024/1024; //计算可用空间
Memo1→Lines→Add(“C盘总空间(Mb):”+String(totalspace));
Memo1→Lines→Add(“C盘可用空间(Mb):”+String(freespace));
*/
//---------------------------------------------------------------------------
// 获取硬件消息
#include <ddraw.h>
#pragma comment(lib, "ddraw.lib")
LPDIRECTDRAW7 lpDD;
//---------------------------------------------------------------------------
void GetHwInformation(char* strResult)
{
HKEY hKey;
DWORD dwMhz,dwSize;
char strDx[256], strCpu[256],strVendor[256],strIdentifier[256],stmp[1024];
strcpy(strResult,"// 机器配置:/n");
// 操作系统版本号:
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
sprintf(stmp,"OS:/n %u,%u,%u,%u/r/n",osvi.dwMajorVersion,osvi.dwMinorVersion,osvi.dwBuildNumber,osvi.dwPlatformId);
strcat(strResult,stmp);
// Dx版本号:
RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE//MICROSOFT//DirectX",0,KEY_QUERY_VALUE,&hKey);
dwSize = sizeof(strDx);
RegQueryValueEx(hKey,"Version",0,0,(LPBYTE)strDx,&dwSize);
RegCloseKey( hKey );
sprintf(stmp,"DX:/n %s/n",strDx);
strcat(strResult,stmp);
// 检测显卡:
GetVideoCardInfo();
std::list<string>::iterator it, end;
it = g_listVideoCard.begin();
end = g_listVideoCard.end();
sprintf(stmp,"VideoCard:/n");
strcat(strResult,stmp);
for(int i=0;it!=end;++it)
{
sprintf(stmp," %s/n",it->c_str());
strcat(strResult,stmp);
}
// 检测显示器
/*
//::GetDeviceCaps();
int tcs;
long int bpp,cp,tc;
Memo1→Lines→Add (“当前分辨率为:”+String(Screen→Width)+“*”+
String(Screen→Height));
bpp=GetDeviceCaps(Form1→Canvas→Handle ,BITSPIXEL);
tcs=pow(2,bpp); //计算色彩的梯度数
cp= GetDeviceCaps(Form1→Canvas→Handle,PLANES);
tc= pow(tcs,cp); //计算色深
Memo1→Lines→Add(“当前色深为:”+String(tc));
*/
// 得到cpu数据:
//SYSTEM_INFO systeminfo; GetSystemInfo (&systeminfo);
RegOpenKeyEx(HKEY_LOCAL_MACHINE,"HARDWARE//DESCRIPTION//System//CentralProcessor//0",0,KEY_QUERY_VALUE,&hKey);
dwMhz = 0;
dwSize = sizeof(dwMhz);
RegQueryValueEx(hKey,"~MHz",0,0,(LPBYTE)&dwMhz,&dwSize);
strcpy(strCpu,"");
dwSize = sizeof(strCpu);
RegQueryValueEx(hKey,"ProcessorNameString",0,0,(LPBYTE)strCpu,&dwSize);
strcpy(strVendor,"");
dwSize = sizeof(strVendor);
RegQueryValueEx(hKey,"VendorIdentifier",0,0,(LPBYTE)strVendor,&dwSize);
strcpy(strIdentifier,"");
dwSize = sizeof(strIdentifier);
RegQueryValueEx(hKey,"Identifier",0,0,(LPBYTE)strIdentifier,&dwSize);
RegCloseKey( hKey );
//sprintf(stmp,"CPU: %dMHz,%s,%s/r/n",(int)dwMhz,strVendor,strCpu);
sprintf(stmp,"CPU:/n %s/n",strCpu);
strcat(strResult,stmp);
sprintf(stmp,"VendorIdentifier:/n %s/n",strVendor);
strcat(strResult,stmp);
sprintf(stmp,"Identifier:/n %s/n",strIdentifier);
strcat(strResult,stmp);
// 得到内存数据:
MEMORYSTATUS ms;
GlobalMemoryStatus(&ms);
sprintf(stmp,"mem(T/F):/n MemoryLoad:%d,/n TotalPhys:%dK, AvailPhys:%dK,/n AvailPageFile:%dK, TotalPageFile:%dK,/n AvailVirtual:%dK,TotalVirtual:%dK/r/n",
ms.dwMemoryLoad,ms.dwTotalPhys/1024,ms.dwAvailPhys/1024,ms.dwAvailPageFile/1024,ms.dwTotalPageFile/1024,ms.dwAvailVirtual/1024,ms.dwTotalVirtual/1024);
strcat(strResult,stmp);
// 得到显存数据:
//////////////////////////////////////////////////
//创建DirectDraw对象
//DirectDrawCreate(NULL, &lpDD, NULL);
DirectDrawCreateEx(NULL, (VOID**)&lpDD, IID_IDirectDraw7, NULL);
DDSCAPS2 ddsCaps;
ZeroMemory(&ddsCaps, sizeof(ddsCaps));
ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
DWORD dwUsedVRAM = 0;
DWORD dwTotal=0;
DWORD dwFree=0;
// lp_DD points to the IDirectDraw object
HRESULT hr = lpDD->GetAvailableVidMem(&ddsCaps, &dwTotal, &dwFree);
// dwUsedVRAM holds the number of bytes of VRAM used
dwUsedVRAM = dwTotal-dwFree;
lpDD->Release();
//////////////////////////////////////////////////
sprintf(stmp,"VideoMemory:/n Total:%fM,Using:%fM,Free:%fM,/n",(float)dwTotal/(float)1000000,(float)dwUsedVRAM/(float)1000000,(float)dwFree/(float)1000000);
strcat(strResult,stmp);
// IDirect3DX* d3d = Direct3DCreateX(D3D_SDK_VERSION);
}