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>
20 typedef struct _IMGINFO
27 PIMGINFO pImgInfo
= NULL
;
30 ShowLastWin32Error(HWND hWndOwner
)
35 LastError
= GetLastError();
37 if ((LastError
== 0) ||
38 !FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
39 FORMAT_MESSAGE_FROM_SYSTEM
,
42 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
50 MessageBox(hWndOwner
, lpMsg
, NULL
, MB_OK
| MB_ICONERROR
);
52 LocalFree((LPVOID
)lpMsg
);
57 InitImageInfo(PIMGINFO ImgInfo
)
61 ZeroMemory(ImgInfo
, sizeof(*ImgInfo
));
63 ImgInfo
->hBitmap
= LoadImage(hApplet
,
64 MAKEINTRESOURCE(IDB_ROSBMP
),
70 if (ImgInfo
->hBitmap
!= NULL
)
72 GetObject(ImgInfo
->hBitmap
, sizeof(BITMAP
), &bitmap
);
74 ImgInfo
->cxSource
= bitmap
.bmWidth
;
75 ImgInfo
->cySource
= bitmap
.bmHeight
;
79 LRESULT CALLBACK
RosImageProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
81 static UINT timerid
= 0, top
= 0, offset
;
82 static HBITMAP hBitmap2
;
91 case WM_LBUTTONDBLCLK
:
92 if (wParam
& (MK_CONTROL
| MK_SHIFT
))
99 GetObject(pImgInfo
->hBitmap
, sizeof(BITMAP
), &bitmap
);
100 dc
= CreateCompatibleDC(GetDC(NULL
));
105 sdc
= CreateCompatibleDC(dc
);
111 ncm
.cbSize
= sizeof(NONCLIENTMETRICS
);
112 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(NONCLIENTMETRICS
), &ncm
, 0);
114 hfont
= CreateFontIndirect(&ncm
.lfMessageFont
);
115 SelectObject(dc
, hfont
);
116 SetRect(&r
, 0, 0, 0, 0);
117 LoadString(hApplet
, IDS_DEVS
, devtext
, sizeof(devtext
) / sizeof(TCHAR
));
118 DrawText(dc
, devtext
, -1, &r
, DT_CALCRECT
);
119 hBitmap2
= CreateBitmap(pImgInfo
->cxSource
, (2 * pImgInfo
->cySource
) + (r
.bottom
+ 1 - r
.top
), bitmap
.bmPlanes
, bitmap
.bmBitsPixel
, NULL
);
120 SelectObject(sdc
, pImgInfo
->hBitmap
);
121 SelectObject(dc
, hBitmap2
);
123 BitBlt(dc
, 0, offset
, bitmap
.bmWidth
, bitmap
.bmHeight
, sdc
, 0, 0, SRCCOPY
);
124 offset
+= bitmap
.bmHeight
;
126 SetRect(&r
, 0, offset
, bitmap
.bmWidth
, offset
+ (r
.bottom
- r
.top
) + 1);
127 FillRect(dc
, &r
, GetSysColorBrush(COLOR_3DFACE
));
128 SetBkMode(dc
, TRANSPARENT
);
129 OffsetRect(&r
, 1, 1);
130 SetTextColor(dc
, GetSysColor(COLOR_BTNSHADOW
));
131 DrawText(dc
, devtext
, -1, &r
, DT_CENTER
);
132 OffsetRect(&r
, -1, -1);
133 SetTextColor(dc
, GetSysColor(COLOR_WINDOWTEXT
));
134 DrawText(dc
, devtext
, -1, &r
, DT_CENTER
);
135 offset
+= r
.bottom
- r
.top
;
137 BitBlt(dc
, 0, offset
, bitmap
.bmWidth
, bitmap
.bmHeight
, sdc
, 0, 0, SRCCOPY
);
138 offset
+= bitmap
.bmHeight
;
142 timerid
= SetTimer(hwnd
, 1, ANIM_TIME
, NULL
);
149 KillTimer(hwnd
, timerid
);
152 DeleteObject(hBitmap2
);
153 InvalidateRect(hwnd
, NULL
, FALSE
);
158 if (top
> offset
- pImgInfo
->cySource
)
160 KillTimer(hwnd
, timerid
);
163 DeleteObject(hBitmap2
);
165 InvalidateRect(hwnd
, NULL
, FALSE
);
178 hdc
= BeginPaint(hwnd
,&PS
);
180 GetClientRect(hwnd
,&PS
.rcPaint
);
182 /* Position image in center of dialog */
183 left
= (PS
.rcPaint
.right
- pImgInfo
->cxSource
) / 2;
184 hdcMem
= CreateCompatibleDC(hdc
);
188 SelectObject(hdcMem
, timerid
? hBitmap2
: pImgInfo
->hBitmap
);
192 PS
.rcPaint
.right
- PS
.rcPaint
.left
,
193 PS
.rcPaint
.top
+ pImgInfo
->cySource
,
210 SetRegTextData(HWND hwnd
,
219 if (RegQueryValueEx(hKey
,
224 &BufSize
) == ERROR_SUCCESS
)
226 lpBuf
= HeapAlloc(GetProcessHeap(),
232 if (RegQueryValueEx(hKey
,
237 &BufSize
) == ERROR_SUCCESS
)
244 HeapFree(GetProcessHeap(),
251 SetProcNameString(HWND hwnd
,
265 if (RegQueryValueEx(hKey
,
270 &BufSize
) == ERROR_SUCCESS
)
272 lpBuf
= HeapAlloc(GetProcessHeap(),
278 if (RegQueryValueEx(hKey
,
283 &BufSize
) == ERROR_SUCCESS
)
285 if (BufSize
> ((30 + 1) * sizeof(TCHAR
)))
287 /* Wrap the Processor Name String like XP does: *
288 * - Take the first 30 characters and look for the last space. *
289 * Then wrap the string after this space. *
290 * - If no space is found, wrap the string after character 30. *
292 * For example the Processor Name String of a Pentium 4 is right-aligned. *
293 * With this wrapping the first line looks centered. */
295 _tcsncpy(szBuf
, lpBuf
, 30);
297 szLastSpace
= _tcsrchr(szBuf
, ' ');
299 if (szLastSpace
== 0)
305 LastSpace
= (szLastSpace
- szBuf
);
306 szBuf
[LastSpace
] = 0;
309 _tcsncpy(szBuf
, lpBuf
, LastSpace
);
319 /* Return the number of used lines */
332 HeapFree(GetProcessHeap(),
341 MakeFloatValueString(double* dFloatValue
,
345 TCHAR szDecimalSeparator
[4];
347 /* Get the decimal separator for the current locale */
348 if (GetLocaleInfo(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, szDecimalSeparator
, sizeof(szDecimalSeparator
) / sizeof(TCHAR
)) > 0)
353 /* Show the value with two decimals */
354 uIntegral
= (UINT
)*dFloatValue
;
355 uDecimals
= (UCHAR
)((UINT
)(*dFloatValue
* 100) - uIntegral
* 100);
357 wsprintf(szOutput
, _T("%u%s%02u %s"), uIntegral
, szDecimalSeparator
, uDecimals
, szAppend
);
362 SetProcSpeed(HWND hwnd
,
368 DWORD BufSize
= sizeof(DWORD
);
370 PROCESSOR_POWER_INFORMATION ppi
;
375 if ((CallNtPowerInformation(ProcessorInformation
,
379 sizeof(ppi
)) == STATUS_SUCCESS
&&
380 ppi
.CurrentMhz
!= 0) ||
381 RegQueryValueEx(hKey
,
385 (PBYTE
)&ppi
.CurrentMhz
,
386 &BufSize
) == ERROR_SUCCESS
)
388 if (ppi
.CurrentMhz
< 1000)
390 wsprintf(szBuf
, _T("%lu MHz"), ppi
.CurrentMhz
);
394 double flt
= ppi
.CurrentMhz
/ 1000.0;
395 MakeFloatValueString(&flt
, szBuf
, _T("GHz"));
405 GetSystemInformation(HWND hwnd
)
408 TCHAR ProcKey
[] = _T("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
409 MEMORYSTATUSEX MemStat
;
411 INT CurMachineLine
= IDC_MACHINELINE1
;
414 * Get Processor information
415 * although undocumented, this information is being pulled
416 * directly out of the registry instead of via setupapi as it
417 * contains all the info we need, and should remain static
419 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
423 &hKey
) == ERROR_SUCCESS
)
427 _T("VendorIdentifier"),
431 CurMachineLine
+= SetProcNameString(hwnd
,
433 _T("ProcessorNameString"),
445 /* Get total physical RAM */
446 MemStat
.dwLength
= sizeof(MemStat
);
447 if (GlobalMemoryStatusEx(&MemStat
))
452 if (MemStat
.ullTotalPhys
> 1024 * 1024 * 1024)
455 static const UINT uStrId
[] = {
461 // We're dealing with GBs or more
462 MemStat
.ullTotalPhys
/= 1024 * 1024;
464 if (MemStat
.ullTotalPhys
> 1024 * 1024)
466 // We're dealing with TBs or more
467 MemStat
.ullTotalPhys
/= 1024;
470 if (MemStat
.ullTotalPhys
> 1024 * 1024)
472 // We're dealing with PBs or more
473 MemStat
.ullTotalPhys
/= 1024;
476 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
480 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
485 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
488 LoadString(hApplet
, uStrId
[i
], szStr
, sizeof(szStr
) / sizeof(TCHAR
));
489 MakeFloatValueString(&dTotalPhys
, Buf
, szStr
);
493 // We're dealing with MBs, don't show any decimals
494 LoadString(hApplet
, IDS_MEGABYTE
, szStr
, sizeof(szStr
) / sizeof(TCHAR
));
495 wsprintf(Buf
, _T("%u %s"), (UINT
)MemStat
.ullTotalPhys
/ 1024 / 1024, szStr
);
498 SetDlgItemText(hwnd
, CurMachineLine
, Buf
);
503 /* Property page dialog callback */
505 GeneralPageProc(HWND hwndDlg
,
511 UNREFERENCED_PARAMETER(lParam
);
512 UNREFERENCED_PARAMETER(wParam
);
517 pImgInfo
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IMGINFO
));
518 if (pImgInfo
== NULL
)
520 EndDialog(hwndDlg
, 0);
524 InitImageInfo(pImgInfo
);
525 SetWindowLongPtr(GetDlgItem(hwndDlg
, IDC_ROSIMG
), GWL_WNDPROC
, (LONG
)RosImageProc
);
526 GetSystemInformation(hwndDlg
);
530 HeapFree(GetProcessHeap(), 0, pImgInfo
);
534 if (LOWORD(wParam
) == IDC_LICENCE
)
537 MAKEINTRESOURCE(IDD_LICENCE
),
547 LPDRAWITEMSTRUCT lpDrawItem
;
548 lpDrawItem
= (LPDRAWITEMSTRUCT
) lParam
;
549 if (lpDrawItem
->CtlID
== IDC_ROSIMG
)
554 /* Position image in centre of dialog */
555 left
= (lpDrawItem
->rcItem
.right
- pImgInfo
->cxSource
) / 2;
557 hdcMem
= CreateCompatibleDC(lpDrawItem
->hDC
);
560 SelectObject(hdcMem
, pImgInfo
->hBitmap
);
561 BitBlt(lpDrawItem
->hDC
,
563 lpDrawItem
->rcItem
.top
,
564 lpDrawItem
->rcItem
.right
- lpDrawItem
->rcItem
.left
,
565 lpDrawItem
->rcItem
.bottom
- lpDrawItem
->rcItem
.top
,
578 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
580 if (nmhdr
->idFrom
== IDC_ROSHOMEPAGE_LINK
&& nmhdr
->code
== NM_CLICK
)
582 PNMLINK nml
= (PNMLINK
)nmhdr
;
584 ShellExecuteW(hwndDlg
,