2 * PROJECT: ReactOS System Control Panel Applet
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/sysdm/general.c
5 * PURPOSE: General System Information
6 * COPYRIGHT: Copyright Thomas Weidenmueller <w3seek@reactos.org>
7 * Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
8 * Copyright 2006-2007 Colin Finck <mail@colinfinck.de>
15 typedef struct _IMGINFO
24 ShowLastWin32Error(HWND hWndOwner
)
29 LastError
= GetLastError();
31 if((LastError
== 0) ||
32 !FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
33 FORMAT_MESSAGE_FROM_SYSTEM
,
36 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
44 MessageBox(hWndOwner
, lpMsg
, NULL
, MB_OK
| MB_ICONERROR
);
46 LocalFree((LPVOID
)lpMsg
);
51 InitImageInfo(PIMGINFO ImgInfo
)
55 ZeroMemory(ImgInfo
, sizeof(*ImgInfo
));
57 ImgInfo
->hBitmap
= LoadImage(hApplet
,
58 MAKEINTRESOURCE(IDB_ROSBMP
),
64 if (ImgInfo
->hBitmap
!= NULL
)
66 GetObject(ImgInfo
->hBitmap
, sizeof(BITMAP
), &bitmap
);
68 ImgInfo
->cxSource
= bitmap
.bmWidth
;
69 ImgInfo
->cySource
= bitmap
.bmHeight
;
75 SetRegTextData(HWND hwnd
,
84 if (RegQueryValueEx(hKey
,
89 &BufSize
) == ERROR_SUCCESS
)
91 lpBuf
= HeapAlloc(GetProcessHeap(),
96 if (RegQueryValueEx(hKey
,
101 &BufSize
) == ERROR_SUCCESS
)
108 HeapFree(GetProcessHeap(),
115 SetProcNameString(HWND hwnd
,
129 if (RegQueryValueEx(hKey
,
134 &BufSize
) == ERROR_SUCCESS
)
136 lpBuf
= HeapAlloc(GetProcessHeap(),
139 if (!lpBuf
) return 0;
141 if (RegQueryValueEx(hKey
,
146 &BufSize
) == ERROR_SUCCESS
)
148 if(BufSize
> ((30 + 1) * sizeof(TCHAR
)))
150 /* Wrap the Processor Name String like XP does: *
151 * - Take the first 30 characters and look for the last space. *
152 * Then wrap the string after this space. *
153 * - If no space is found, wrap the string after character 30. *
155 * For example the Processor Name String of a Pentium 4 is right-aligned. *
156 * With this wrapping the first line looks centered. */
158 _tcsncpy(szBuf
, lpBuf
, 30);
160 szLastSpace
= _tcsrchr(szBuf
, ' ');
166 LastSpace
= (szLastSpace
- szBuf
);
167 szBuf
[LastSpace
] = 0;
170 _tcsncpy(szBuf
, lpBuf
, LastSpace
);
180 /* Return the number of used lines */
193 HeapFree(GetProcessHeap(),
202 SetProcSpeed(HWND hwnd
,
209 DWORD BufSize
= sizeof(DWORD
);
211 PROCESSOR_POWER_INFORMATION ppi
;
216 if ((CallNtPowerInformation(ProcessorInformation
,
220 sizeof(ppi
)) == STATUS_SUCCESS
&&
221 ppi
.CurrentMhz
!= 0) ||
222 RegQueryValueEx(hKey
,
226 (PBYTE
)&ppi
.CurrentMhz
,
227 &BufSize
) == ERROR_SUCCESS
)
229 if (ppi
.CurrentMhz
< 1000)
231 _stprintf(szBuf
, _T("%lu MHz"), ppi
.CurrentMhz
);
235 double flt
= ppi
.CurrentMhz
/ 1000.0;
236 _stprintf(szBuf
, _T("%.2f GHz"), flt
);
246 GetSystemInformation(HWND hwnd
)
249 TCHAR ProcKey
[] = _T("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
250 MEMORYSTATUSEX MemStat
;
252 INT CurMachineLine
= IDC_MACHINELINE1
;
255 /* Get Processor information *
256 * although undocumented, this information is being pulled
257 * directly out of the registry instead of via setupapi as it
258 * contains all the info we need, and should remain static
260 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
264 &hKey
) == ERROR_SUCCESS
)
268 _T("VendorIdentifier"),
272 CurMachineLine
+= SetProcNameString(hwnd
,
274 _T("ProcessorNameString"),
286 /* Get total physical RAM */
287 MemStat
.dwLength
= sizeof(MemStat
);
288 if (GlobalMemoryStatusEx(&MemStat
))
293 static const UINT uStrId
[] = {
300 if (MemStat
.ullTotalPhys
> 1024 * 1024 * 1024)
302 /* We're dealing with GBs or more */
303 MemStat
.ullTotalPhys
/= 1024 * 1024;
306 if (MemStat
.ullTotalPhys
> 1024 * 1024)
308 /* We're dealing with TBs or more */
309 MemStat
.ullTotalPhys
/= 1024;
312 if (MemStat
.ullTotalPhys
> 1024 * 1024)
314 /* We're dealing with PBs or more */
315 MemStat
.ullTotalPhys
/= 1024;
318 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
321 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
324 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
328 /* We're daling with MBs */
329 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024 / 1024;
332 if (LoadString(hApplet
, uStrId
[i
], szStr
, sizeof(szStr
) / sizeof(szStr
[0])))
334 if( _stprintf(Buf
, _T("%.2f %s"), dTotalPhys
, szStr
) )
345 /* Property page dialog callback */
347 GeneralPageProc(HWND hwndDlg
,
352 static IMGINFO ImgInfo
;
354 UNREFERENCED_PARAMETER(lParam
);
355 UNREFERENCED_PARAMETER(wParam
);
361 InitImageInfo(&ImgInfo
);
362 GetSystemInformation(hwndDlg
);
368 if (LOWORD(wParam
) == IDC_LICENCE
)
371 MAKEINTRESOURCE(IDD_LICENCE
),
382 LPDRAWITEMSTRUCT lpDrawItem
;
383 lpDrawItem
= (LPDRAWITEMSTRUCT
) lParam
;
384 if(lpDrawItem
->CtlID
== IDC_ROSIMG
)
389 /* position image in centre of dialog */
390 left
= (lpDrawItem
->rcItem
.right
- ImgInfo
.cxSource
) / 2;
392 hdcMem
= CreateCompatibleDC(lpDrawItem
->hDC
);
395 SelectObject(hdcMem
, ImgInfo
.hBitmap
);
396 BitBlt(lpDrawItem
->hDC
,
398 lpDrawItem
->rcItem
.top
,
399 lpDrawItem
->rcItem
.right
- lpDrawItem
->rcItem
.left
,
400 lpDrawItem
->rcItem
.bottom
- lpDrawItem
->rcItem
.top
,
413 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
415 if (nmhdr
->idFrom
== IDC_ROSHOMEPAGE_LINK
&& nmhdr
->code
== NM_CLICK
)
417 PNMLINK nml
= (PNMLINK
)nmhdr
;
419 ShellExecuteW(hwndDlg
,