* Slap *some* sense into our header inclusions.
[reactos.git] / reactos / dll / shellext / devcpux / processor.c
1 /*
2 * PROJECT: ReactOS Shell Extensions
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: dll\win32\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
21 #include "resource.h"
22
23 HINSTANCE g_hInstance = NULL;
24 INT_PTR CALLBACK ProcessorDlgProc (HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam);
25
26 BOOL
27 APIENTRY
28 DllMain (HANDLE hInstance, DWORD dwReason, LPVOID lpReserved)
29 {
30 switch (dwReason)
31 {
32 case DLL_THREAD_ATTACH:
33 case DLL_THREAD_DETACH:
34 case DLL_PROCESS_ATTACH:
35 case DLL_PROCESS_DETACH:
36 break;
37 }
38
39 g_hInstance = (HINSTANCE) hInstance;
40 return TRUE;
41 }
42
43
44 BOOL
45 APIENTRY
46 PropSheetExtProc(PSP_PROPSHEETPAGE_REQUEST PropPageRequest, LPFNADDPROPSHEETPAGE fAddFunc, LPARAM lParam)
47 {
48 PROPSHEETPAGE PropSheetPage;
49 HPROPSHEETPAGE hPropSheetPage;
50
51 if(PropPageRequest->PageRequested != SPPSR_ENUM_ADV_DEVICE_PROPERTIES)
52 return FALSE;
53
54 if ((!PropPageRequest->DeviceInfoSet) || (!PropPageRequest->DeviceInfoData))
55 return FALSE;
56
57 ZeroMemory(&PropSheetPage, sizeof(PROPSHEETPAGE));
58 PropSheetPage.dwSize = sizeof(PROPSHEETPAGE);
59 PropSheetPage.hInstance = g_hInstance;
60 PropSheetPage.pszTemplate = MAKEINTRESOURCE(DLG_PROCESSORINFO);
61 PropSheetPage.pfnDlgProc = ProcessorDlgProc;
62
63 hPropSheetPage = CreatePropertySheetPage(&PropSheetPage);
64 if(!hPropSheetPage)
65 return FALSE;
66
67 if(!(fAddFunc)(hPropSheetPage, lParam)) {
68 DestroyPropertySheetPage (hPropSheetPage);
69 return FALSE;
70 }
71
72 return TRUE;
73 }
74
75 void
76 AddFeature(WCHAR* szFeatures, WCHAR* Feature, BOOL* bFirst)
77 {
78 if (!*bFirst)
79 wcscat(szFeatures, L", ");
80 *bFirst = FALSE;
81 wcscat(szFeatures, Feature);
82 }
83
84 INT_PTR
85 CALLBACK
86 ProcessorDlgProc (HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
87 {
88 switch (uMessage) {
89 case WM_INITDIALOG:
90 {
91 WCHAR szFeatures[MAX_PATH] = L"";
92 WCHAR szModel[3];
93 WCHAR szStepping[3];
94 WCHAR szCurrentMhz[10];
95 BOOL bFirst = TRUE;
96 SYSTEM_INFO SystemInfo;
97 PROCESSOR_POWER_INFORMATION PowerInfo;
98
99 if (IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE))
100 AddFeature(szFeatures, L"MMX", &bFirst);
101 if (IsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE))
102 AddFeature(szFeatures, L"SSE", &bFirst);
103 if (IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE))
104 AddFeature(szFeatures, L"SSE2", &bFirst);
105 /*if (IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE))
106 AddFeature(szFeatures, L"SSE3", &bFirst); */
107 if (IsProcessorFeaturePresent(PF_3DNOW_INSTRUCTIONS_AVAILABLE))
108 AddFeature(szFeatures, L"3DNOW", &bFirst);
109
110 SetDlgItemTextW(hDlg, IDC_FEATURES, szFeatures);
111
112 GetSystemInfo(&SystemInfo);
113
114 wsprintf(szModel, L"%x", HIBYTE(SystemInfo.wProcessorRevision));
115 wsprintf(szStepping, L"%d", LOBYTE(SystemInfo.wProcessorRevision));
116
117 SetDlgItemTextW(hDlg, IDC_MODEL, szModel);
118 SetDlgItemTextW(hDlg, IDC_STEPPING, szStepping);
119
120 CallNtPowerInformation(11, NULL, 0, &PowerInfo, sizeof(PowerInfo));
121 wsprintf(szCurrentMhz, L"%ld %s", PowerInfo.CurrentMhz, L"MHz");
122 SetDlgItemTextW(hDlg, IDC_CORESPEED, szCurrentMhz);
123
124 return TRUE;
125 }
126 }
127 return FALSE;
128 }