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>
18 typedef struct _IMGINFO
25 PIMGINFO pImgInfo
= NULL
;
28 ShowLastWin32Error(HWND hWndOwner
)
33 LastError
= GetLastError();
35 if ((LastError
== 0) ||
36 !FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
37 FORMAT_MESSAGE_FROM_SYSTEM
,
40 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
48 MessageBox(hWndOwner
, lpMsg
, NULL
, MB_OK
| MB_ICONERROR
);
50 LocalFree((LPVOID
)lpMsg
);
55 InitImageInfo(PIMGINFO ImgInfo
)
59 ZeroMemory(ImgInfo
, sizeof(*ImgInfo
));
61 ImgInfo
->hBitmap
= LoadImage(hApplet
,
62 MAKEINTRESOURCE(IDB_ROSBMP
),
68 if (ImgInfo
->hBitmap
!= NULL
)
70 GetObject(ImgInfo
->hBitmap
, sizeof(BITMAP
), &bitmap
);
72 ImgInfo
->cxSource
= bitmap
.bmWidth
;
73 ImgInfo
->cySource
= bitmap
.bmHeight
;
77 LRESULT CALLBACK
RosImageProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
79 static UINT timerid
= 0, top
= 0, offset
;
80 static HBITMAP hBitmap2
;
89 case WM_LBUTTONDBLCLK
:
90 if (wParam
& (MK_CONTROL
| MK_SHIFT
))
97 GetObject(pImgInfo
->hBitmap
, sizeof(BITMAP
), &bitmap
);
98 dc
= CreateCompatibleDC(GetDC(NULL
));
99 sdc
= CreateCompatibleDC(dc
);
100 ncm
.cbSize
= sizeof(NONCLIENTMETRICS
);
101 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(NONCLIENTMETRICS
), &ncm
, 0);
103 hfont
= CreateFontIndirect(&ncm
.lfMessageFont
);
104 SelectObject(dc
, hfont
);
105 SetRect(&r
, 0, 0, 0, 0);
106 LoadString(hApplet
, IDS_DEVS
, devtext
, sizeof(devtext
) / sizeof(TCHAR
));
107 DrawText(dc
, devtext
, -1, &r
, DT_CALCRECT
);
108 hBitmap2
= CreateBitmap(pImgInfo
->cxSource
, (2 * pImgInfo
->cySource
) + (r
.bottom
+ 1 - r
.top
), bitmap
.bmPlanes
, bitmap
.bmBitsPixel
, NULL
);
109 SelectObject(sdc
, pImgInfo
->hBitmap
);
110 SelectObject(dc
, hBitmap2
);
112 BitBlt(dc
, 0, offset
, bitmap
.bmWidth
, bitmap
.bmHeight
, sdc
, 0, 0, SRCCOPY
);
113 offset
+= bitmap
.bmHeight
;
115 SetRect(&r
, 0, offset
, bitmap
.bmWidth
, offset
+ (r
.bottom
- r
.top
) + 1);
116 FillRect(dc
, &r
, GetSysColorBrush(COLOR_3DFACE
));
117 SetBkMode(dc
, TRANSPARENT
);
118 OffsetRect(&r
, 1, 1);
119 SetTextColor(dc
, GetSysColor(COLOR_BTNSHADOW
));
120 DrawText(dc
, devtext
, -1, &r
, DT_CENTER
);
121 OffsetRect(&r
, -1, -1);
122 SetTextColor(dc
, GetSysColor(COLOR_WINDOWTEXT
));
123 DrawText(dc
, devtext
, -1, &r
, DT_CENTER
);
124 offset
+= r
.bottom
- r
.top
;
126 BitBlt(dc
, 0, offset
, bitmap
.bmWidth
, bitmap
.bmHeight
, sdc
, 0, 0, SRCCOPY
);
127 offset
+= bitmap
.bmHeight
;
131 timerid
= SetTimer(hwnd
, 1, ANIM_TIME
, NULL
);
138 KillTimer(hwnd
, timerid
);
141 DeleteObject(hBitmap2
);
142 InvalidateRect(hwnd
, NULL
, FALSE
);
147 if (top
> offset
- pImgInfo
->cySource
)
149 KillTimer(hwnd
, timerid
);
152 DeleteObject(hBitmap2
);
154 InvalidateRect(hwnd
, NULL
, FALSE
);
166 hdc
= BeginPaint(hwnd
,&PS
);
168 GetClientRect(hwnd
,&PS
.rcPaint
);
170 /* position image in center of dialog */
171 left
= (PS
.rcPaint
.right
- pImgInfo
->cxSource
) / 2;
172 hdcMem
= CreateCompatibleDC(hdc
);
176 SelectObject(hdcMem
, timerid
? hBitmap2
: pImgInfo
->hBitmap
);
180 PS
.rcPaint
.right
- PS
.rcPaint
.left
,
181 PS
.rcPaint
.top
+ pImgInfo
->cySource
,
197 SetRegTextData(HWND hwnd
,
206 if (RegQueryValueEx(hKey
,
211 &BufSize
) == ERROR_SUCCESS
)
213 lpBuf
= HeapAlloc(GetProcessHeap(),
219 if (RegQueryValueEx(hKey
,
224 &BufSize
) == ERROR_SUCCESS
)
231 HeapFree(GetProcessHeap(),
238 SetProcNameString(HWND hwnd
,
252 if (RegQueryValueEx(hKey
,
257 &BufSize
) == ERROR_SUCCESS
)
259 lpBuf
= HeapAlloc(GetProcessHeap(),
265 if (RegQueryValueEx(hKey
,
270 &BufSize
) == ERROR_SUCCESS
)
272 if (BufSize
> ((30 + 1) * sizeof(TCHAR
)))
274 /* Wrap the Processor Name String like XP does: *
275 * - Take the first 30 characters and look for the last space. *
276 * Then wrap the string after this space. *
277 * - If no space is found, wrap the string after character 30. *
279 * For example the Processor Name String of a Pentium 4 is right-aligned. *
280 * With this wrapping the first line looks centered. */
282 _tcsncpy(szBuf
, lpBuf
, 30);
284 szLastSpace
= _tcsrchr(szBuf
, ' ');
286 if (szLastSpace
== 0)
292 LastSpace
= (szLastSpace
- szBuf
);
293 szBuf
[LastSpace
] = 0;
296 _tcsncpy(szBuf
, lpBuf
, LastSpace
);
306 /* Return the number of used lines */
319 HeapFree(GetProcessHeap(),
328 MakeFloatValueString(double* dFloatValue
,
332 TCHAR szDecimalSeparator
[4];
334 /* Get the decimal separator for the current locale */
335 if (GetLocaleInfo(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, szDecimalSeparator
, sizeof(szDecimalSeparator
) / sizeof(TCHAR
)) > 0)
340 /* Show the value with two decimals */
341 uIntegral
= (UINT
)*dFloatValue
;
342 uDecimals
= (UCHAR
)((UINT
)(*dFloatValue
* 100) - uIntegral
* 100);
344 wsprintf(szOutput
, _T("%u%s%02u %s"), uIntegral
, szDecimalSeparator
, uDecimals
, szAppend
);
349 SetProcSpeed(HWND hwnd
,
355 DWORD BufSize
= sizeof(DWORD
);
357 PROCESSOR_POWER_INFORMATION ppi
;
362 if ((CallNtPowerInformation(ProcessorInformation
,
366 sizeof(ppi
)) == STATUS_SUCCESS
&&
367 ppi
.CurrentMhz
!= 0) ||
368 RegQueryValueEx(hKey
,
372 (PBYTE
)&ppi
.CurrentMhz
,
373 &BufSize
) == ERROR_SUCCESS
)
375 if (ppi
.CurrentMhz
< 1000)
377 wsprintf(szBuf
, _T("%lu MHz"), ppi
.CurrentMhz
);
381 double flt
= ppi
.CurrentMhz
/ 1000.0;
382 MakeFloatValueString(&flt
, szBuf
, _T("GHz"));
392 GetSystemInformation(HWND hwnd
)
395 TCHAR ProcKey
[] = _T("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
396 MEMORYSTATUSEX MemStat
;
398 INT CurMachineLine
= IDC_MACHINELINE1
;
401 * Get Processor information
402 * although undocumented, this information is being pulled
403 * directly out of the registry instead of via setupapi as it
404 * contains all the info we need, and should remain static
406 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
410 &hKey
) == ERROR_SUCCESS
)
414 _T("VendorIdentifier"),
418 CurMachineLine
+= SetProcNameString(hwnd
,
420 _T("ProcessorNameString"),
432 /* Get total physical RAM */
433 MemStat
.dwLength
= sizeof(MemStat
);
434 if (GlobalMemoryStatusEx(&MemStat
))
439 if (MemStat
.ullTotalPhys
> 1024 * 1024 * 1024)
442 static const UINT uStrId
[] = {
448 // We're dealing with GBs or more
449 MemStat
.ullTotalPhys
/= 1024 * 1024;
451 if (MemStat
.ullTotalPhys
> 1024 * 1024)
453 // We're dealing with TBs or more
454 MemStat
.ullTotalPhys
/= 1024;
457 if (MemStat
.ullTotalPhys
> 1024 * 1024)
459 // We're dealing with PBs or more
460 MemStat
.ullTotalPhys
/= 1024;
463 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
467 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
472 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
475 LoadString(hApplet
, uStrId
[i
], szStr
, sizeof(szStr
) / sizeof(TCHAR
));
476 MakeFloatValueString(&dTotalPhys
, Buf
, szStr
);
480 // We're dealing with MBs, don't show any decimals
481 LoadString(hApplet
, IDS_MEGABYTE
, szStr
, sizeof(szStr
) / sizeof(TCHAR
));
482 wsprintf(Buf
, _T("%u %s"), (UINT
)MemStat
.ullTotalPhys
/ 1024 / 1024, szStr
);
485 SetDlgItemText(hwnd
, CurMachineLine
, Buf
);
490 /* Property page dialog callback */
492 GeneralPageProc(HWND hwndDlg
,
498 UNREFERENCED_PARAMETER(lParam
);
499 UNREFERENCED_PARAMETER(wParam
);
504 pImgInfo
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IMGINFO
));
505 if (pImgInfo
== NULL
)
507 EndDialog(hwndDlg
, 0);
511 InitImageInfo(pImgInfo
);
512 SetWindowLongPtr(GetDlgItem(hwndDlg
, IDC_ROSIMG
), GWL_WNDPROC
, (LONG
)RosImageProc
);
513 GetSystemInformation(hwndDlg
);
517 HeapFree(GetProcessHeap(), 0, pImgInfo
);
521 if (LOWORD(wParam
) == IDC_LICENCE
)
524 MAKEINTRESOURCE(IDD_LICENCE
),
534 LPDRAWITEMSTRUCT lpDrawItem
;
535 lpDrawItem
= (LPDRAWITEMSTRUCT
) lParam
;
536 if (lpDrawItem
->CtlID
== IDC_ROSIMG
)
541 /* position image in centre of dialog */
542 left
= (lpDrawItem
->rcItem
.right
- pImgInfo
->cxSource
) / 2;
544 hdcMem
= CreateCompatibleDC(lpDrawItem
->hDC
);
547 SelectObject(hdcMem
, pImgInfo
->hBitmap
);
548 BitBlt(lpDrawItem
->hDC
,
550 lpDrawItem
->rcItem
.top
,
551 lpDrawItem
->rcItem
.right
- lpDrawItem
->rcItem
.left
,
552 lpDrawItem
->rcItem
.bottom
- lpDrawItem
->rcItem
.top
,
565 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
567 if (nmhdr
->idFrom
== IDC_ROSHOMEPAGE_LINK
&& nmhdr
->code
== NM_CLICK
)
569 PNMLINK nml
= (PNMLINK
)nmhdr
;
571 ShellExecuteW(hwndDlg
,