ReactOS 0.4.16-dev-1946-g52006dd
powercfg.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Power Configuration Applet
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Applet initialization
5 * COPYRIGHT: Copyright 2006-2009 Alexander Wurzinger <lohnegrim@gmx.net>
6 * Copyright 2006 Johannes Anderwald <johannes.anderwald@reactos.org>
7 * Copyright 2006 Martin Rottensteiner <2005only@pianonote.at>
8 */
9
10#include "powercfg.h"
11
12#include <winreg.h>
13#include <regstr.h>
14
18
19static BOOL CALLBACK
21{
23 if (ppsh != NULL && ppsh->nPages < MAX_POWER_PAGES)
24 {
25 ppsh->phpage[ppsh->nPages++] = hpage;
26 return TRUE;
27 }
28
29 return FALSE;
30}
31
32static BOOL
34{
35 HPROPSHEETPAGE hPage;
36 PROPSHEETPAGE psp;
37
38 if (ppsh->nPages < MAX_POWER_PAGES)
39 {
40 ZeroMemory(&psp, sizeof(psp));
41 psp.dwSize = sizeof(psp);
42 psp.dwFlags = PSP_DEFAULT;
43 psp.hInstance = hApplet;
44 psp.pszTemplate = MAKEINTRESOURCE(idDlg);
45 psp.pfnDlgProc = DlgProc;
46
47 hPage = CreatePropertySheetPage(&psp);
48 if (hPage != NULL)
49 {
50 return PropSheetAddPage(hPage, (LPARAM)ppsh);
51 }
52 }
53
54 return FALSE;
55}
56
57static int CALLBACK
59{
60 // NOTE: This callback is needed to set large icon correctly.
62
63 switch (uMsg)
64 {
66 {
68 SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
69 break;
70 }
71 }
72 return 0;
73}
74
75/* First Applet */
76static LONG APIENTRY
78{
81 HPSXA hpsxa = NULL;
83 LONG ret;
84
88
89 ZeroMemory(&psh, sizeof(psh));
90 psh.dwSize = sizeof(psh);
92 psh.hwndParent = hwnd;
93 psh.hInstance = hApplet;
94 psh.pszIcon = MAKEINTRESOURCEW(IDC_CPLICON);
95 psh.pszCaption = MAKEINTRESOURCEW(IDS_CPLNAME);
96 psh.nPages = 0;
97 psh.nStartPage = 0;
98 psh.phpage = hpsp;
99 psh.pfnCallback = PropSheetProc;
100
101 if (!GetPwrCapabilities(&spc))
102 return GetLastError();
103
105 {
109 }
110 else
111 {
113 }
115 if (spc.SystemS4)
116 {
117 /* ACPI S4 state is supported, display the "Hibernate" page
118 * where we can enable or disable the hibernation file */
120 }
121
122 // TODO: Add UPS page (check spc.UpsPresent)
123
124 /* Load additional pages provided by shell extensions */
126 if (hpsxa != NULL)
128
129 ret = (LONG)(PropertySheet(&psh) != -1);
130
131 if (hpsxa != NULL)
133
134 return ret;
135}
136
137/* Control Panel Callback */
138#define NUM_APPLETS 1
141 UINT uMsg,
142 LPARAM lParam1,
143 LPARAM lParam2)
144{
145 UINT i = (UINT)lParam1;
146
147 switch (uMsg)
148 {
149 case CPL_INIT:
150 return TRUE;
151
152 case CPL_GETCOUNT:
153 return NUM_APPLETS;
154
155 case CPL_INQUIRE:
156 if (i < NUM_APPLETS)
157 {
158 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
159 CPlInfo->lData = 0;
160 CPlInfo->idIcon = IDC_CPLICON;
161 CPlInfo->idName = IDS_CPLNAME;
162 CPlInfo->idInfo = IDS_CPLDESCRIPTION;
163 }
164 else
165 {
166 return TRUE;
167 }
168 break;
169
170 case CPL_DBLCLK:
171 if (i < NUM_APPLETS)
172 Applet(hwndCPl, uMsg, lParam1, lParam2);
173 else
174 return TRUE;
175 break;
176 }
177
178 return FALSE;
179}
180
181
186{
188
189 switch (dwReason)
190 {
193 hApplet = hinstDLL;
194 break;
195 }
196
197 return TRUE;
198}
unsigned char BOOLEAN
INT_PTR CALLBACK AlarmsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: alarms.c:151
DWORD dwReason
Definition: misc.cpp:135
static INT_PTR CALLBACK AdvancedDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
Definition: charmap.c:480
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define CPL_INQUIRE
Definition: cpl.h:14
#define CPL_DBLCLK
Definition: cpl.h:16
#define CPL_INIT
Definition: cpl.h:12
#define CPL_GETCOUNT
Definition: cpl.h:13
#define DLGPROC
Definition: maze.c:62
WORD idDlg
Definition: desk.c:121
DLGPROC DlgProc
Definition: desk.c:122
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define IDC_CPLICON
Definition: resource.h:7
#define IDS_CPLNAME
Definition: resource.h:8
#define IDS_CPLDESCRIPTION
Definition: resource.h:9
#define IDD_PROPPAGEPOWERMETER
Definition: resource.h:56
#define IDD_POWERSCHEMESPAGE_ACDC
Definition: resource.h:53
#define IDD_PROPPAGEHIBERNATE
Definition: resource.h:58
#define IDD_POWERSCHEMESPAGE_AC
Definition: resource.h:54
#define IDD_PROPPAGEADVANCED
Definition: resource.h:57
#define IDD_PROPPAGEALARMS
Definition: resource.h:55
#define APIENTRY
Definition: api.h:79
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define CALLBACK
Definition: compat.h:35
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
return ret
Definition: mutex.c:146
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
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
INT_PTR CALLBACK HibernateDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: hibernate.c:87
#define TEXT(s)
Definition: k32.h:28
static IN DWORD IN LPVOID lpvReserved
#define ZeroMemory
Definition: minwinbase.h:31
LONG_PTR LPARAM
Definition: minwindef.h:175
static HICON
Definition: imagelist.c:80
HICON hIcon
Definition: msconfig.c:44
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
unsigned int UINT
Definition: ndis.h:50
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
#define MAKEINTRESOURCE(i)
Definition: ntverrsrc.c:25
long LONG
Definition: pedump.c:60
static BOOL InitPropSheetPage(PROPSHEETHEADER *ppsh, WORD idDlg, DLGPROC DlgProc)
Definition: powercfg.c:33
#define NUM_APPLETS
Definition: powercfg.c:138
static BOOL CALLBACK PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam)
Definition: powercfg.c:20
static int CALLBACK PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
Definition: powercfg.c:58
TCHAR langSel[255]
Definition: powercfg.c:17
static LONG APIENTRY Applet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
Definition: powercfg.c:77
BOOLEAN WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
Definition: powercfg.c:183
GLOBAL_POWER_POLICY gGPP
Definition: powercfg.c:16
HINSTANCE hApplet
Definition: powercfg.c:15
INT_PTR CALLBACK PowerSchemesDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: powershemes.c:826
INT_PTR CALLBACK PowerMeterDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: powermeter.c:481
#define MAX_POWER_PAGES
Definition: powercfg.h:41
BOOLEAN WINAPI GetPwrCapabilities(PSYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities)
Definition: powrprof.c:582
#define PROPSHEETHEADER
Definition: prsht.h:392
#define PSH_PROPTITLE
Definition: prsht.h:40
#define CreatePropertySheetPage
Definition: prsht.h:399
#define PSH_USECALLBACK
Definition: prsht.h:48
#define PSP_DEFAULT
Definition: prsht.h:22
#define PropertySheet
Definition: prsht.h:400
#define PSH_USEICONID
Definition: prsht.h:42
#define PSCB_INITIALIZED
Definition: prsht.h:75
#define PROPSHEETPAGE
Definition: prsht.h:389
#define REGSTR_PATH_CONTROLSFOLDER
Definition: regstr.h:76
void WINAPI SHDestroyPropSheetExtArray(HPSXA hpsxa)
Definition: shellord.c:2396
UINT WINAPI SHAddFromPropSheetExtArray(HPSXA hpsxa, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
Definition: shellord.c:2219
HPSXA WINAPI SHCreatePropSheetExtArray(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface)
Definition: shellord.c:2249
BOOLEAN SystemBatteriesPresent
Definition: ntpoapi.h:374
Definition: cpl.h:24
LONG_PTR lData
Definition: cpl.h:28
int idName
Definition: cpl.h:26
int idInfo
Definition: cpl.h:27
int idIcon
Definition: cpl.h:25
#define ICON_BIG
Definition: tnclass.cpp:51
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define WINAPI
Definition: msvc.h:6
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE hInstance, _In_ LPCWSTR lpIconName)
Definition: cursoricon.c:2427
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
char TCHAR
Definition: xmlstorage.h:189