xref: /reactos/dll/shellext/devcpux/processor.c (revision a6726659)
1 /*
2  * PROJECT:     ReactOS Shell Extensions
3  * LICENSE:     LGPL - See COPYING in the top level directory
4  * FILE:        dll/shellext/devcpux/processor.c
5  * PURPOSE:
6  * COPYRIGHT:   Copyright 2007 Christoph von Wittich <Christoph_vW@ReactOS.org>
7  *
8  */
9 
10 #define WIN32_NO_STATUS
11 #define _INC_WINDOWS
12 #define COM_NO_WINDOWS_H
13 #include <stdarg.h>
14 #include <windef.h>
15 #include <winbase.h>
16 #include <winreg.h>
17 #include <winuser.h>
18 #include <setupapi.h>
19 #include <powrprof.h>
20 #include <strsafe.h>
21 
22 #include "resource.h"
23 
24 HINSTANCE g_hInstance = NULL;
25 INT_PTR CALLBACK ProcessorDlgProc (HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam);
26 
27 BOOL
28 APIENTRY
29 DllMain (HANDLE hInstance, DWORD dwReason, LPVOID lpReserved)
30 {
31     switch (dwReason)
32     {
33         case DLL_THREAD_ATTACH:
34         case DLL_THREAD_DETACH:
35         case DLL_PROCESS_ATTACH:
36         case DLL_PROCESS_DETACH:
37             break;
38     }
39 
40     g_hInstance = (HINSTANCE) hInstance;
41     return TRUE;
42 }
43 
44 
45 BOOL
46 APIENTRY
47 PropSheetExtProc(PSP_PROPSHEETPAGE_REQUEST PropPageRequest, LPFNADDPROPSHEETPAGE fAddFunc, LPARAM lParam)
48 {
49     PROPSHEETPAGE PropSheetPage;
50     HPROPSHEETPAGE hPropSheetPage;
51 
52     if(PropPageRequest->PageRequested != SPPSR_ENUM_ADV_DEVICE_PROPERTIES)
53         return FALSE;
54 
55     if ((!PropPageRequest->DeviceInfoSet) || (!PropPageRequest->DeviceInfoData))
56         return FALSE;
57 
58     ZeroMemory(&PropSheetPage, sizeof(PROPSHEETPAGE));
59     PropSheetPage.dwSize = sizeof(PROPSHEETPAGE);
60     PropSheetPage.hInstance = g_hInstance;
61     PropSheetPage.pszTemplate = MAKEINTRESOURCE(DLG_PROCESSORINFO);
62     PropSheetPage.pfnDlgProc = ProcessorDlgProc;
63 
64     hPropSheetPage = CreatePropertySheetPage(&PropSheetPage);
65     if(!hPropSheetPage)
66         return FALSE;
67 
68     if(!(fAddFunc)(hPropSheetPage, lParam)) {
69         DestroyPropertySheetPage (hPropSheetPage);
70         return FALSE;
71     }
72 
73     return TRUE;
74 }
75 
76 void
77 AddFeature(WCHAR* szFeatures, size_t cbDest, WCHAR* Feature, BOOL* bFirst)
78 {
79     if (!*bFirst)
80         StringCbCatW(szFeatures, cbDest, L", ");
81     *bFirst = FALSE;
82     StringCbCatW(szFeatures, cbDest, Feature);
83 }
84 
85 INT_PTR
86 CALLBACK
87 ProcessorDlgProc (HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
88 {
89     switch (uMessage) {
90         case WM_INITDIALOG:
91         {
92             WCHAR szFeatures[MAX_PATH] = L"";
93             WCHAR szModel[3];
94             WCHAR szStepping[3];
95             WCHAR szMhz[16];
96             WCHAR szCurrentMhz[10];
97             BOOL bFirst = TRUE;
98             SYSTEM_INFO SystemInfo;
99             PROCESSOR_POWER_INFORMATION PowerInfo;
100 
101             if (!LoadStringW(g_hInstance, IDS_MEGAHERTZ, szMhz, ARRAYSIZE(szMhz)))
102             {
103                 StringCbCopyW(szMhz, sizeof(szMhz), L"%ld MHz");
104             }
105 
106             if (IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE))
107                 AddFeature(szFeatures, sizeof(szFeatures), L"MMX", &bFirst);
108             if (IsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE))
109                 AddFeature(szFeatures, sizeof(szFeatures), L"SSE", &bFirst);
110             if (IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE))
111                 AddFeature(szFeatures, sizeof(szFeatures), L"SSE2", &bFirst);
112             /*if (IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE))
113                 AddFeature(szFeatures, sizeof(szFeatures), L"SSE3", &bFirst); */
114             if (IsProcessorFeaturePresent(PF_3DNOW_INSTRUCTIONS_AVAILABLE))
115                 AddFeature(szFeatures, sizeof(szFeatures), L"3DNOW", &bFirst);
116 
117             SetDlgItemTextW(hDlg, IDC_FEATURES, szFeatures);
118 
119             GetSystemInfo(&SystemInfo);
120 
121             StringCbPrintfW(szModel, sizeof(szModel), L"%x", HIBYTE(SystemInfo.wProcessorRevision));
122             StringCbPrintfW(szStepping, sizeof(szStepping), L"%d", LOBYTE(SystemInfo.wProcessorRevision));
123 
124             SetDlgItemTextW(hDlg, IDC_MODEL, szModel);
125             SetDlgItemTextW(hDlg, IDC_STEPPING, szStepping);
126 
127             CallNtPowerInformation(11, NULL, 0, &PowerInfo, sizeof(PowerInfo));
128             StringCbPrintfW(szCurrentMhz, sizeof(szCurrentMhz), szMhz, PowerInfo.CurrentMhz);
129             SetDlgItemTextW(hDlg, IDC_CORESPEED, szCurrentMhz);
130 
131             return TRUE;
132         }
133     }
134     return FALSE;
135 }
136