xref: /reactos/dll/shellext/devcpux/processor.c (revision 845faec4)
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 szCurrentMhz[10];
96             BOOL bFirst = TRUE;
97             SYSTEM_INFO SystemInfo;
98             PROCESSOR_POWER_INFORMATION PowerInfo;
99 
100             if (IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE))
101                 AddFeature(szFeatures, sizeof(szFeatures), L"MMX", &bFirst);
102             if (IsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE))
103                 AddFeature(szFeatures, sizeof(szFeatures), L"SSE", &bFirst);
104             if (IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE))
105                 AddFeature(szFeatures, sizeof(szFeatures), L"SSE2", &bFirst);
106             /*if (IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE))
107                 AddFeature(szFeatures, sizeof(szFeatures), L"SSE3", &bFirst); */
108             if (IsProcessorFeaturePresent(PF_3DNOW_INSTRUCTIONS_AVAILABLE))
109                 AddFeature(szFeatures, sizeof(szFeatures), L"3DNOW", &bFirst);
110 
111             SetDlgItemTextW(hDlg, IDC_FEATURES, szFeatures);
112 
113             GetSystemInfo(&SystemInfo);
114 
115             StringCbPrintfW(szModel, sizeof(szModel), L"%x", HIBYTE(SystemInfo.wProcessorRevision));
116             StringCbPrintfW(szStepping, sizeof(szStepping), L"%d", LOBYTE(SystemInfo.wProcessorRevision));
117 
118             SetDlgItemTextW(hDlg, IDC_MODEL, szModel);
119             SetDlgItemTextW(hDlg, IDC_STEPPING, szStepping);
120 
121             CallNtPowerInformation(11, NULL, 0, &PowerInfo, sizeof(PowerInfo));
122             StringCbPrintfW(szCurrentMhz, sizeof(szCurrentMhz), L"%ld %s", PowerInfo.CurrentMhz, L"MHz");
123             SetDlgItemTextW(hDlg, IDC_CORESPEED, szCurrentMhz);
124 
125             return TRUE;
126         }
127     }
128     return FALSE;
129 }
130