2013-03-16 20:25:38 +00:00
|
|
|
/*
|
2006-06-15 14:16:29 +00:00
|
|
|
* PROJECT: ReactOS Power Configuration Applet
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2015-09-22 17:04:32 +00:00
|
|
|
* FILE: dll/cpl/powercfg/powercfg.c
|
2006-06-15 14:16:29 +00:00
|
|
|
* PURPOSE: initialization of applet
|
|
|
|
* PROGRAMMERS: Alexander Wurzinger (Lohnegrim at gmx dot net)
|
2013-09-15 13:06:05 +00:00
|
|
|
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
2006-06-15 14:16:29 +00:00
|
|
|
* Martin Rottensteiner
|
2007-11-30 18:52:33 +00:00
|
|
|
* Dmitry Chapyshev (lentind@yandex.ru)
|
2006-06-15 14:16:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "powercfg.h"
|
|
|
|
|
2014-01-19 10:37:02 +00:00
|
|
|
#include <winreg.h>
|
|
|
|
#include <regstr.h>
|
|
|
|
|
2015-09-07 21:56:38 +00:00
|
|
|
#define NUM_APPLETS (1)
|
2006-06-15 14:16:29 +00:00
|
|
|
|
2007-07-28 20:02:37 +00:00
|
|
|
static LONG APIENTRY Applet1(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam);
|
2007-12-02 14:25:17 +00:00
|
|
|
|
2006-06-15 14:16:29 +00:00
|
|
|
|
|
|
|
HINSTANCE hApplet = 0;
|
|
|
|
GLOBAL_POWER_POLICY gGPP;
|
2006-06-23 17:14:29 +00:00
|
|
|
TCHAR langSel[255];
|
2006-06-15 14:16:29 +00:00
|
|
|
|
|
|
|
/* Applets */
|
2007-10-19 23:21:45 +00:00
|
|
|
APPLET Applets[NUM_APPLETS] =
|
2006-06-15 14:16:29 +00:00
|
|
|
{
|
2019-05-01 11:16:00 +00:00
|
|
|
{IDC_CPLICON_1, IDS_CPLNAME_1, IDS_CPLDESCRIPTION_1, Applet1}
|
2006-06-15 14:16:29 +00:00
|
|
|
};
|
|
|
|
|
2007-09-22 18:59:23 +00:00
|
|
|
static BOOL CALLBACK
|
|
|
|
PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam)
|
|
|
|
{
|
|
|
|
PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)lParam;
|
|
|
|
if (ppsh != NULL && ppsh->nPages < MAX_POWER_PAGES)
|
|
|
|
{
|
|
|
|
ppsh->phpage[ppsh->nPages++] = hpage;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
InitPropSheetPage(PROPSHEETHEADER *ppsh, WORD idDlg, DLGPROC DlgProc)
|
2006-06-15 14:16:29 +00:00
|
|
|
{
|
2007-09-22 18:59:23 +00:00
|
|
|
HPROPSHEETPAGE hPage;
|
|
|
|
PROPSHEETPAGE psp;
|
|
|
|
|
|
|
|
if (ppsh->nPages < MAX_POWER_PAGES)
|
|
|
|
{
|
|
|
|
ZeroMemory(&psp, sizeof(psp));
|
|
|
|
psp.dwSize = sizeof(psp);
|
|
|
|
psp.dwFlags = PSP_DEFAULT;
|
|
|
|
psp.hInstance = hApplet;
|
|
|
|
psp.pszTemplate = MAKEINTRESOURCE(idDlg);
|
|
|
|
psp.pfnDlgProc = DlgProc;
|
|
|
|
|
|
|
|
hPage = CreatePropertySheetPage(&psp);
|
|
|
|
if (hPage != NULL)
|
|
|
|
{
|
|
|
|
return PropSheetAddPage(hPage, (LPARAM)ppsh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2006-06-15 14:16:29 +00:00
|
|
|
}
|
|
|
|
|
2018-12-14 11:06:57 +00:00
|
|
|
static int CALLBACK
|
|
|
|
PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
|
|
|
|
{
|
|
|
|
// NOTE: This callback is needed to set large icon correctly.
|
|
|
|
HICON hIcon;
|
2019-05-01 11:16:00 +00:00
|
|
|
|
2018-12-14 11:06:57 +00:00
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case PSCB_INITIALIZED:
|
|
|
|
{
|
|
|
|
hIcon = LoadIconW(hApplet, MAKEINTRESOURCEW(IDC_CPLICON_1));
|
|
|
|
SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-06-15 14:16:29 +00:00
|
|
|
|
|
|
|
/* First Applet */
|
2007-07-28 20:02:37 +00:00
|
|
|
static LONG APIENTRY
|
2007-10-19 23:21:45 +00:00
|
|
|
Applet1(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
|
2006-06-15 14:16:29 +00:00
|
|
|
{
|
2019-05-01 11:16:00 +00:00
|
|
|
HPROPSHEETPAGE hpsp[MAX_POWER_PAGES];
|
|
|
|
PROPSHEETHEADER psh;
|
|
|
|
HPSXA hpsxa = NULL;
|
|
|
|
SYSTEM_POWER_CAPABILITIES spc;
|
|
|
|
LONG ret;
|
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(uMsg);
|
|
|
|
UNREFERENCED_PARAMETER(wParam);
|
|
|
|
UNREFERENCED_PARAMETER(lParam);
|
|
|
|
|
|
|
|
ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
|
|
|
|
psh.dwSize = sizeof(PROPSHEETHEADER);
|
|
|
|
psh.dwFlags = PSH_PROPTITLE | PSH_USEICONID | PSH_USECALLBACK;
|
|
|
|
psh.hwndParent = hwnd;
|
|
|
|
psh.hInstance = hApplet;
|
|
|
|
psh.pszIcon = MAKEINTRESOURCEW(IDC_CPLICON_1);
|
2022-08-27 14:01:55 +00:00
|
|
|
psh.pszCaption = MAKEINTRESOURCEW(IDS_CPLNAME_1);
|
2019-05-01 11:16:00 +00:00
|
|
|
psh.nPages = 0;
|
|
|
|
psh.nStartPage = 0;
|
|
|
|
psh.phpage = hpsp;
|
|
|
|
psh.pfnCallback = PropSheetProc;
|
|
|
|
|
2019-05-12 21:48:36 +00:00
|
|
|
if (!GetPwrCapabilities(&spc))
|
2015-09-07 21:56:38 +00:00
|
|
|
{
|
2019-05-12 21:48:36 +00:00
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spc.SystemBatteriesPresent)
|
|
|
|
{
|
|
|
|
InitPropSheetPage(&psh, IDD_POWERSCHEMESPAGE_ACDC, PowerSchemesDlgProc);
|
|
|
|
InitPropSheetPage(&psh, IDD_PROPPAGEALARMS, AlarmsDlgProc);
|
2020-03-15 15:06:49 +00:00
|
|
|
|
|
|
|
/* FIXME: Add battery page */
|
2019-05-12 21:48:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
InitPropSheetPage(&psh, IDD_POWERSCHEMESPAGE_AC, PowerSchemesDlgProc);
|
2015-09-07 21:56:38 +00:00
|
|
|
}
|
2019-05-01 11:16:00 +00:00
|
|
|
InitPropSheetPage(&psh, IDD_PROPPAGEADVANCED, AdvancedDlgProc);
|
2019-05-12 21:52:08 +00:00
|
|
|
if (spc.SystemS4)
|
|
|
|
{
|
|
|
|
InitPropSheetPage(&psh, IDD_PROPPAGEHIBERNATE, HibernateDlgProc);
|
|
|
|
}
|
2007-09-22 18:48:02 +00:00
|
|
|
|
2020-03-15 15:06:49 +00:00
|
|
|
/* FIXME: Add UPS page */
|
|
|
|
|
2019-05-01 11:16:00 +00:00
|
|
|
/* Load additional pages provided by shell extensions */
|
|
|
|
hpsxa = SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Power"), MAX_POWER_PAGES - psh.nPages);
|
|
|
|
if (hpsxa != NULL)
|
|
|
|
SHAddFromPropSheetExtArray(hpsxa, PropSheetAddPage, (LPARAM)&psh);
|
2007-09-22 18:48:02 +00:00
|
|
|
|
2019-05-01 11:16:00 +00:00
|
|
|
ret = (LONG)(PropertySheet(&psh) != -1);
|
2007-09-22 18:48:02 +00:00
|
|
|
|
2019-05-01 11:16:00 +00:00
|
|
|
if (hpsxa != NULL)
|
|
|
|
SHDestroyPropSheetExtArray(hpsxa);
|
2007-09-22 18:48:02 +00:00
|
|
|
|
2019-05-01 11:16:00 +00:00
|
|
|
return ret;
|
2006-06-15 14:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Control Panel Callback */
|
|
|
|
LONG CALLBACK
|
2007-12-02 14:25:17 +00:00
|
|
|
CPlApplet(HWND hwndCPl,
|
|
|
|
UINT uMsg,
|
|
|
|
LPARAM lParam1,
|
|
|
|
LPARAM lParam2)
|
2006-06-15 14:16:29 +00:00
|
|
|
{
|
2019-05-01 11:16:00 +00:00
|
|
|
int i = (int)lParam1;
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2019-05-01 11:16:00 +00:00
|
|
|
switch (uMsg)
|
2006-06-15 14:16:29 +00:00
|
|
|
{
|
2019-05-01 11:16:00 +00:00
|
|
|
case CPL_INIT:
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CPL_GETCOUNT:
|
|
|
|
{
|
|
|
|
return NUM_APPLETS;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CPL_INQUIRE:
|
|
|
|
{
|
|
|
|
CPLINFO *CPlInfo = (CPLINFO*)lParam2;
|
|
|
|
CPlInfo->lData = 0;
|
|
|
|
CPlInfo->idIcon = Applets[i].idIcon;
|
|
|
|
CPlInfo->idName = Applets[i].idName;
|
|
|
|
CPlInfo->idInfo = Applets[i].idDescription;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CPL_DBLCLK:
|
|
|
|
{
|
|
|
|
Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
|
|
|
|
break;
|
|
|
|
}
|
2006-06-15 14:16:29 +00:00
|
|
|
}
|
2019-05-01 11:16:00 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2006-06-15 14:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-02 14:25:17 +00:00
|
|
|
BOOLEAN WINAPI
|
|
|
|
DllMain(HINSTANCE hinstDLL,
|
|
|
|
DWORD dwReason,
|
|
|
|
LPVOID lpvReserved)
|
2006-06-15 14:16:29 +00:00
|
|
|
{
|
2019-05-01 11:16:00 +00:00
|
|
|
UNREFERENCED_PARAMETER(lpvReserved);
|
|
|
|
|
2019-05-12 21:48:36 +00:00
|
|
|
switch (dwReason)
|
2019-05-01 11:16:00 +00:00
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2019-05-12 21:48:36 +00:00
|
|
|
DisableThreadLibraryCalls(hinstDLL);
|
2019-05-01 11:16:00 +00:00
|
|
|
hApplet = hinstDLL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2006-06-15 14:16:29 +00:00
|
|
|
}
|