11. november 2001 - 15:35
#1
Ok, mange tak.
Jeg poster lige koden igen, så det giver mening for andre...
Jeg sender hele projektet til dig i en .zip
Dette kode viser hvordan man finder nogle info.
Jeg har anvendt MFC, så hvis du ikke gør det, skal der foretages et par ændringer...
//Code to get system devices
//Memory
MEMORYSTATUS MS;
GlobalMemoryStatus(&MS);
m_AvailMem = MS.dwMemoryLoad; //percent of memory in use
m_PhysMem = MS.dwTotalPhys/1048576; //Mbytes of physical memory
m_FreePhysMem = MS.dwAvailPhys/1048576; //free physical memory Mbytes
m_PageFile = MS.dwTotalPageFile/1048576; //Mbytes of paging file
m_FreePageFile = MS.dwAvailPageFile/1048576; //free Mbytes of paging file
m_AdrSpace = MS.dwTotalVirtual/1048576; //user Mbytes of address space
m_UserBytes = MS.dwAvailVirtual/1048576; //free user Mbytes
//Printers
CString Printers;
DWORD dwSize, dwPrinters;
::EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, NULL, 0, &dwSize, &dwPrinters);
BYTE* pBuffer = new BYTE[dwSize];
::EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, pBuffer, dwSize, &dwSize, &dwPrinters);
if(dwPrinters != 0)
{
PRINTER_INFO_5* pPrnInfo = (PRINTER_INFO_5*)pBuffer;
for(UINT i=0; i<dwPrinters; ++i)
{
CString PrinterDevice = pPrnInfo->pPrinterName;
PrinterDevice += \" at \";
PrinterDevice += pPrnInfo->pPortName;
m_PrinterList.AddString(PrinterDevice);
++pPrnInfo;
}
}
delete[] pBuffer;
//Graphics
DEVMODE DM;
::EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &DM);
DWORD Width = DM.dmPelsWidth;
DWORD Height = DM.dmPelsHeight;
DWORD BitsPerPix = DM.dmBitsPerPel;
CString Display;
Display.Format(\"%d x %d x %d\", Width, Height, BitsPerPix);
m_CurrentGraphicsMode = Display;
//All supported modes
int i=0;
while(::EnumDisplaySettings(NULL, i, &DM))
{
DWORD Width = DM.dmPelsWidth;
DWORD Height = DM.dmPelsHeight;
DWORD BitsPerPix = DM.dmBitsPerPel;
//CString Name = DM.dmDeviceName;//returns \"\"!!!
WORD ver = DM.dmDriverVersion;
CString Display;
Display.Format(\"%d x %d x %d\", Width, Height, BitsPerPix);
m_SupportedModes.AddString(Display);
++i;
}
//Monitors/output
DWORD bufsize, nrOfmonitors;
::EnumMonitors(NULL, 1, NULL, 0, &bufsize, &nrOfmonitors);
BYTE* pMonitorBuffer = new BYTE[bufsize];
::EnumMonitors(NULL, 1, pMonitorBuffer, bufsize, &bufsize, &nrOfmonitors);
if(nrOfmonitors != 0)
{
MONITOR_INFO_1* pMonInfo = (MONITOR_INFO_1*)pMonitorBuffer;
for(UINT i=0; i<nrOfmonitors; ++i)
{
CString Monitor = pMonInfo->pName;
m_Monitors.AddString(Monitor);
++pMonInfo;
}
}
delete[] pMonitorBuffer;
//Windows
CString version;
version.Format(\"%d.%d\", _winmajor, _winminor);
m_WinVersion = version;
m_Build = _osver;
//Processor(s)
SYSTEM_INFO SI;
GetSystemInfo(&SI);
m_NumOfProcessors = SI.dwNumberOfProcessors;
m_ProcessorType = SI.dwProcessorType;
WORD ProcessorLevel = SI.wProcessorLevel;
DWORD mask = SI.dwActiveProcessorMask;