ReactOS  0.4.15-dev-5463-g138eb58
powercfg.c
Go to the documentation of this file.
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 
20 
21 
25 
26 /* Applets */
28 {
30 };
31 
32 static BOOL CALLBACK
34 {
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
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 static int CALLBACK
72 {
73  // NOTE: This callback is needed to set large icon correctly.
74  HICON hIcon;
75 
76  switch (uMsg)
77  {
78  case PSCB_INITIALIZED:
79  {
81  SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
82  break;
83  }
84  }
85  return 0;
86 }
87 
88 /* First Applet */
89 static LONG APIENTRY
91 {
93  PROPSHEETHEADER psh;
94  HPSXA hpsxa = NULL;
96  LONG ret;
97 
101 
102  ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
103  psh.dwSize = sizeof(PROPSHEETHEADER);
104  psh.dwFlags = PSH_PROPTITLE | PSH_USEICONID | PSH_USECALLBACK;
105  psh.hwndParent = hwnd;
106  psh.hInstance = hApplet;
107  psh.pszIcon = MAKEINTRESOURCEW(IDC_CPLICON_1);
108  psh.pszCaption = MAKEINTRESOURCEW(IDS_CPLNAME_1);
109  psh.nPages = 0;
110  psh.nStartPage = 0;
111  psh.phpage = hpsp;
112  psh.pfnCallback = PropSheetProc;
113 
114  if (!GetPwrCapabilities(&spc))
115  {
116  return GetLastError();
117  }
118 
119  if (spc.SystemBatteriesPresent)
120  {
123 
124  /* FIXME: Add battery page */
125  }
126  else
127  {
129  }
131  if (spc.SystemS4)
132  {
134  }
135 
136  /* FIXME: Add UPS page */
137 
138  /* Load additional pages provided by shell extensions */
140  if (hpsxa != NULL)
142 
143  ret = (LONG)(PropertySheet(&psh) != -1);
144 
145  if (hpsxa != NULL)
147 
148  return ret;
149 }
150 
151 /* Control Panel Callback */
153 CPlApplet(HWND hwndCPl,
154  UINT uMsg,
155  LPARAM lParam1,
156  LPARAM lParam2)
157 {
158  UINT i = (UINT)lParam1;
159 
160  switch (uMsg)
161  {
162  case CPL_INIT:
163  {
164  return TRUE;
165  }
166 
167  case CPL_GETCOUNT:
168  {
169  return NUM_APPLETS;
170  }
171 
172  case CPL_INQUIRE:
173  if (i < NUM_APPLETS)
174  {
175  CPLINFO *CPlInfo = (CPLINFO*)lParam2;
176  CPlInfo->lData = 0;
177  CPlInfo->idIcon = Applets[i].idIcon;
178  CPlInfo->idName = Applets[i].idName;
179  CPlInfo->idInfo = Applets[i].idDescription;
180  }
181  else
182  {
183  return TRUE;
184  }
185  break;
186 
187  case CPL_DBLCLK:
188  if (i < NUM_APPLETS)
189  Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
190  else
191  return TRUE;
192  break;
193  }
194 
195  return FALSE;
196 }
197 
198 
201  DWORD dwReason,
203 {
205 
206  switch (dwReason)
207  {
208  case DLL_PROCESS_ATTACH:
209  DisableThreadLibraryCalls(hinstDLL);
210  hApplet = hinstDLL;
211  break;
212  }
213 
214  return TRUE;
215 }
void WINAPI SHDestroyPropSheetExtArray(HPSXA hpsxa)
Definition: shellord.c:2150
TCHAR langSel[255]
Definition: powercfg.c:24
WORD idDlg
Definition: desk.c:110
#define MAKEINTRESOURCE
Definition: winuser.h:591
static HICON
Definition: imagelist.c:84
Definition: cpl.h:24
#define IDD_POWERSCHEMESPAGE_AC
Definition: resource.h:15
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
UINT WINAPI SHAddFromPropSheetExtArray(HPSXA hpsxa, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
Definition: shellord.c:1973
int idName
Definition: hotplug.h:36
#define REGSTR_PATH_CONTROLSFOLDER
Definition: regstr.h:76
int idIcon
Definition: hotplug.h:35
#define CALLBACK
Definition: compat.h:35
BOOLEAN SystemBatteriesPresent
Definition: ntpoapi.h:374
int idInfo
Definition: cpl.h:27
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
BOOLEAN WINAPI GetPwrCapabilities(PSYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities)
Definition: powrprof.c:358
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define ZeroMemory
Definition: winbase.h:1670
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define IDS_CPLDESCRIPTION_1
Definition: resource.h:8
#define PSH_USECALLBACK
Definition: prsht.h:48
WPARAM wParam
Definition: combotst.c:138
static IN DWORD IN LPVOID lpvReserved
int idIcon
Definition: cpl.h:25
int idDescription
Definition: hotplug.h:37
#define CPL_DBLCLK
Definition: cpl.h:16
#define IDD_PROPPAGEALARMS
Definition: resource.h:16
DWORD dwReason
Definition: misc.cpp:154
#define PSH_USEICONID
Definition: prsht.h:42
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
static LONG APIENTRY Applet1(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
Definition: powercfg.c:90
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
unsigned char BOOLEAN
#define PROPSHEETHEADER
Definition: prsht.h:392
static BOOL CALLBACK PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam)
Definition: powercfg.c:33
LONG_PTR LPARAM
Definition: windef.h:208
#define IDS_CPLNAME_1
Definition: resource.h:6
#define CreatePropertySheetPage
Definition: prsht.h:399
GLOBAL_POWER_POLICY gGPP
Definition: powercfg.c:23
char TCHAR
Definition: xmlstorage.h:189
INT_PTR CALLBACK PowerSchemesDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: powershemes.c:825
#define PSP_DEFAULT
Definition: prsht.h:22
#define PSH_PROPTITLE
Definition: prsht.h:40
BOOLEAN WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
Definition: powercfg.c:200
APPLET_PROC AppletProc
Definition: hotplug.h:38
#define WINAPI
Definition: msvc.h:6
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IDD_POWERSCHEMESPAGE_ACDC
Definition: resource.h:14
#define CPL_INIT
Definition: cpl.h:12
int ret
#define CPL_INQUIRE
Definition: cpl.h:14
static BOOL InitPropSheetPage(PROPSHEETHEADER *ppsh, WORD idDlg, DLGPROC DlgProc)
Definition: powercfg.c:46
INT_PTR CALLBACK HibernateDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: hibernate.c:90
LONG_PTR lData
Definition: cpl.h:28
int idName
Definition: cpl.h:26
static int CALLBACK PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
Definition: powercfg.c:71
INT_PTR(CALLBACK * DLGPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2886
#define TEXT(s)
Definition: k32.h:26
INT_PTR CALLBACK AlarmsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: alarms.c:167
#define PSCB_INITIALIZED
Definition: prsht.h:75
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static INT_PTR CALLBACK AdvancedDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
Definition: charmap.c:480
HICON hIcon
Definition: msconfig.c:44
HINSTANCE hApplet
Definition: powercfg.c:22
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDD_PROPPAGEHIBERNATE
Definition: resource.h:19
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
APPLET Applets[NUM_APPLETS]
Definition: powercfg.c:27
#define NUM_APPLETS
Definition: powercfg.c:17
#define PropertySheet
Definition: prsht.h:400
#define IDC_CPLICON_1
Definition: resource.h:4
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2044
#define MAX_POWER_PAGES
Definition: powercfg.h:35
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
HPSXA WINAPI SHCreatePropSheetExtArray(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface)
Definition: shellord.c:2003
#define IDD_PROPPAGEADVANCED
Definition: resource.h:18
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4022
LPARAM lParam
Definition: combotst.c:139
LONG CALLBACK CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
Definition: powercfg.c:153
DLGPROC DlgProc
Definition: desk.c:111
#define CPL_GETCOUNT
Definition: cpl.h:13
#define PROPSHEETPAGE
Definition: prsht.h:389
#define APIENTRY
Definition: api.h:79
#define ICON_BIG
Definition: tnclass.cpp:51
Definition: hotplug.h:33
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12