ReactOS  0.4.14-dev-604-gcfdd483
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;
95  TCHAR Caption[1024];
97  LONG ret;
98 
102 
103  memset(Caption, 0x0, sizeof(Caption));
104  LoadString(hApplet, IDS_CPLNAME_1, Caption, sizeof(Caption) / sizeof(TCHAR));
105 
106  ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
107  psh.dwSize = sizeof(PROPSHEETHEADER);
108  psh.dwFlags = PSH_PROPTITLE | PSH_USEICONID | PSH_USECALLBACK;
109  psh.hwndParent = hwnd;
110  psh.hInstance = hApplet;
111  psh.pszIcon = MAKEINTRESOURCEW(IDC_CPLICON_1);
112  psh.pszCaption = Caption;
113  psh.nPages = 0;
114  psh.nStartPage = 0;
115  psh.phpage = hpsp;
116  psh.pfnCallback = PropSheetProc;
117 
118  if (!GetPwrCapabilities(&spc))
119  {
120  return GetLastError();
121  }
122 
123  if (spc.SystemBatteriesPresent)
124  {
127  }
128  else
129  {
131  }
133  if (spc.SystemS4)
134  {
136  }
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  int i = (int)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  {
174  CPLINFO *CPlInfo = (CPLINFO*)lParam2;
175  CPlInfo->lData = 0;
176  CPlInfo->idIcon = Applets[i].idIcon;
177  CPlInfo->idName = Applets[i].idName;
178  CPlInfo->idInfo = Applets[i].idDescription;
179  break;
180  }
181 
182  case CPL_DBLCLK:
183  {
184  Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
185  break;
186  }
187  }
188 
189  return FALSE;
190 }
191 
192 
195  DWORD dwReason,
197 {
199 
200  switch (dwReason)
201  {
202  case DLL_PROCESS_ATTACH:
203  DisableThreadLibraryCalls(hinstDLL);
204  hApplet = hinstDLL;
205  break;
206  }
207 
208  return TRUE;
209 }
void WINAPI SHDestroyPropSheetExtArray(HPSXA hpsxa)
Definition: shellord.c:1755
TCHAR langSel[255]
Definition: powercfg.c:24
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
WORD idDlg
Definition: desk.c:109
#define MAKEINTRESOURCE
Definition: winuser.h:591
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
Definition: cpl.h:24
GLint x0
Definition: linetemp.h:95
#define IDD_POWERSCHEMESPAGE_AC
Definition: resource.h:15
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
UINT WINAPI SHAddFromPropSheetExtArray(HPSXA hpsxa, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
Definition: shellord.c:1577
int idName
Definition: hotplug.h:27
#define REGSTR_PATH_CONTROLSFOLDER
Definition: regstr.h:76
int idIcon
Definition: hotplug.h:26
#define CALLBACK
Definition: compat.h:27
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:1059
#define ZeroMemory
Definition: winbase.h:1642
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
#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:28
#define CPL_DBLCLK
Definition: cpl.h:16
#define IDD_PROPPAGEALARMS
Definition: resource.h:16
DWORD dwReason
Definition: misc.cpp:154
INT_PTR CALLBACK AdvancedDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: advanced.c:225
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
#define PSH_USEICONID
Definition: prsht.h:42
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
smooth NULL
Definition: ftsmooth.c:416
#define PROPSHEETHEADER
Definition: prsht.h:374
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:381
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:808
#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:194
APPLET_PROC AppletProc
Definition: hotplug.h:29
#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:83
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:2871
#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
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
APPLET Applets[NUM_APPLETS]
Definition: powercfg.c:27
#define NUM_APPLETS
Definition: powercfg.c:17
#define PropertySheet
Definition: prsht.h:382
#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:36
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
HPSXA WINAPI SHCreatePropSheetExtArray(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface)
Definition: shellord.c:1607
#define IDD_PROPPAGEADVANCED
Definition: resource.h:18
#define memset(x, y, z)
Definition: compat.h:39
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:110
#define CPL_GETCOUNT
Definition: cpl.h:13
#define LoadString
Definition: winuser.h:5794
#define PROPSHEETPAGE
Definition: prsht.h:371
#define APIENTRY
Definition: api.h:79
#define ICON_BIG
Definition: tnclass.cpp:51
Definition: hotplug.h:24
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12