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