fd820cc6d29e873ee511bcbce9c6d53d85f90ecf
[reactos.git] / dll / cpl / powercfg / powercfg.c
1 /*
2 * PROJECT: ReactOS Power Configuration Applet
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/powercfg/powercfg.c
5 * PURPOSE: initialization of applet
6 * PROGRAMMERS: Alexander Wurzinger (Lohnegrim at gmx dot net)
7 * Johannes Anderwald (johannes.anderwald@reactos.org)
8 * Martin Rottensteiner
9 * Dmitry Chapyshev (lentind@yandex.ru)
10 */
11
12 #include "powercfg.h"
13
14 #include <winreg.h>
15 #include <regstr.h>
16
17 #define NUM_APPLETS (1)
18
19 static LONG APIENTRY Applet1(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam);
20
21
22 HINSTANCE hApplet = 0;
23 GLOBAL_POWER_POLICY gGPP;
24 TCHAR langSel[255];
25
26 /* Applets */
27 APPLET Applets[NUM_APPLETS] =
28 {
29 {IDC_CPLICON_1, IDS_CPLNAME_1, IDS_CPLDESCRIPTION_1, Applet1}
30 };
31
32 static BOOL CALLBACK
33 PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam)
34 {
35 PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)lParam;
36 if (ppsh != NULL && ppsh->nPages < MAX_POWER_PAGES)
37 {
38 ppsh->phpage[ppsh->nPages++] = hpage;
39 return TRUE;
40 }
41
42 return FALSE;
43 }
44
45 static BOOL
46 InitPropSheetPage(PROPSHEETHEADER *ppsh, WORD idDlg, DLGPROC DlgProc)
47 {
48 HPROPSHEETPAGE hPage;
49 PROPSHEETPAGE psp;
50
51 if (ppsh->nPages < MAX_POWER_PAGES)
52 {
53 ZeroMemory(&psp, sizeof(psp));
54 psp.dwSize = sizeof(psp);
55 psp.dwFlags = PSP_DEFAULT;
56 psp.hInstance = hApplet;
57 psp.pszTemplate = MAKEINTRESOURCE(idDlg);
58 psp.pfnDlgProc = DlgProc;
59
60 hPage = CreatePropertySheetPage(&psp);
61 if (hPage != NULL)
62 {
63 return PropSheetAddPage(hPage, (LPARAM)ppsh);
64 }
65 }
66
67 return FALSE;
68 }
69
70
71 /* First Applet */
72 static LONG APIENTRY
73 Applet1(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
74 {
75 HPROPSHEETPAGE hpsp[MAX_POWER_PAGES];
76 PROPSHEETHEADER psh;
77 HPSXA hpsxa = NULL;
78 TCHAR Caption[1024];
79 SYSTEM_POWER_CAPABILITIES spc;
80 LONG ret;
81
82 UNREFERENCED_PARAMETER(uMsg);
83 UNREFERENCED_PARAMETER(wParam);
84 UNREFERENCED_PARAMETER(lParam);
85
86 memset(Caption, 0x0, sizeof(Caption));
87 LoadString(hApplet, IDS_CPLNAME_1, Caption, sizeof(Caption) / sizeof(TCHAR));
88
89 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
90 psh.dwSize = sizeof(PROPSHEETHEADER);
91 psh.dwFlags = PSH_PROPTITLE;
92 psh.hwndParent = hwnd;
93 psh.hInstance = hApplet;
94 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON_1));
95 psh.pszCaption = Caption;
96 psh.nPages = 0;
97 psh.nStartPage = 0;
98 psh.phpage = hpsp;
99
100 InitPropSheetPage(&psh, IDD_PROPPAGEPOWERSCHEMES, PowerSchemesDlgProc);
101 if (GetPwrCapabilities(&spc))
102 {
103 if (spc.SystemBatteriesPresent)
104 {
105 InitPropSheetPage(&psh, IDD_PROPPAGEALARMS, AlarmsDlgProc);
106 }
107 }
108 InitPropSheetPage(&psh, IDD_PROPPAGEADVANCED, AdvancedDlgProc);
109 InitPropSheetPage(&psh, IDD_PROPPAGEHIBERNATE, HibernateDlgProc);
110
111 /* Load additional pages provided by shell extensions */
112 hpsxa = SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Power"), MAX_POWER_PAGES - psh.nPages);
113 if (hpsxa != NULL)
114 SHAddFromPropSheetExtArray(hpsxa, PropSheetAddPage, (LPARAM)&psh);
115
116 ret = (LONG)(PropertySheet(&psh) != -1);
117
118 if (hpsxa != NULL)
119 SHDestroyPropSheetExtArray(hpsxa);
120
121 return ret;
122 }
123
124 /* Control Panel Callback */
125 LONG CALLBACK
126 CPlApplet(HWND hwndCPl,
127 UINT uMsg,
128 LPARAM lParam1,
129 LPARAM lParam2)
130 {
131 int i = (int)lParam1;
132
133 switch(uMsg)
134 {
135 case CPL_INIT:
136 {
137 return TRUE;
138 }
139 case CPL_GETCOUNT:
140 {
141 return NUM_APPLETS;
142 }
143 case CPL_INQUIRE:
144 {
145 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
146 CPlInfo->lData = 0;
147 CPlInfo->idIcon = Applets[i].idIcon;
148 CPlInfo->idName = Applets[i].idName;
149 CPlInfo->idInfo = Applets[i].idDescription;
150 break;
151 }
152 case CPL_DBLCLK:
153 {
154 Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
155 break;
156 }
157 }
158 return FALSE;
159 }
160
161
162 BOOLEAN WINAPI
163 DllMain(HINSTANCE hinstDLL,
164 DWORD dwReason,
165 LPVOID lpvReserved)
166 {
167 UNREFERENCED_PARAMETER(lpvReserved);
168 switch(dwReason)
169 {
170 case DLL_PROCESS_ATTACH:
171 case DLL_THREAD_ATTACH:
172 hApplet = hinstDLL;
173 break;
174 }
175 return TRUE;
176 }