ReactOS 0.4.15-dev-8093-g3285f69
hibernate.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/hibernate.c
5 * PURPOSE: hibernate tab 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
14static VOID
16{
18 MEMORYSTATUSEX msex;
19 TCHAR szTemp[MAX_PATH];
20 LPTSTR lpRoot;
21 ULARGE_INTEGER FreeBytesAvailable, TotalNumberOfBytes, TotalNumberOfFreeBytes;
22 BOOLEAN bHibernate;
23
24 if (GetPwrCapabilities(&PowerCaps))
25 {
26 CheckDlgButton(hwndDlg,
29
30 msex.dwLength = sizeof(msex);
31 if (!GlobalMemoryStatusEx(&msex))
32 {
33 return; // FIXME
34 }
35
36 if (GetWindowsDirectory(szTemp,MAX_PATH))
37 lpRoot = szTemp;
38 else
39 lpRoot = NULL;
40
41 // Get available space and size of selected volume.
42 if (!GetDiskFreeSpaceEx(lpRoot, &FreeBytesAvailable, &TotalNumberOfBytes, &TotalNumberOfFreeBytes))
43 TotalNumberOfFreeBytes.QuadPart = 0;
44
45 // Print the free available space into selected volume.
46 StrFormatByteSize(TotalNumberOfFreeBytes.QuadPart, szTemp, _countof(szTemp));
47 SetDlgItemText(hwndDlg, IDC_FREESPACE, szTemp);
48
49 // Print the amount of space required for hibernation.
50 StrFormatByteSize(msex.ullTotalPhys, szTemp, _countof(szTemp));
52
53 if (TotalNumberOfFreeBytes.QuadPart < msex.ullTotalPhys && !PowerCaps.HiberFilePresent)
54 {
57 }
58 else
59 {
62 }
63
64 bHibernate = PowerCaps.HiberFilePresent ? TRUE : FALSE;
65 if (CallNtPowerInformation(SystemReserveHiberFile, &bHibernate, sizeof(bHibernate), NULL, 0) != STATUS_SUCCESS)
66 {
68 }
69 }
70}
71
74{
75 BOOLEAN bHibernate;
76
77 bHibernate = (BOOLEAN)(IsDlgButtonChecked(hwndDlg, IDC_HIBERNATEFILE) == BST_CHECKED);
78
79 if (CallNtPowerInformation(SystemReserveHiberFile, &bHibernate, sizeof(bHibernate), NULL, 0) == STATUS_SUCCESS)
80 {
81 Hib_InitDialog(hwndDlg);
82 return TRUE;
83 }
84
85 return FALSE;
86}
87
88/* Property page dialog callback */
91 UINT uMsg,
94{
95 switch (uMsg)
96 {
97 case WM_INITDIALOG:
98 Hib_InitDialog(hwndDlg);
99 return TRUE;
100
101 case WM_COMMAND:
102 switch (LOWORD(wParam))
103 {
105 if (HIWORD(wParam) == BN_CLICKED)
106 {
107 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
108 }
109 break;
110 }
111 break;
112
113 case WM_NOTIFY:
114 if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY)
115 {
116 return Hib_SaveData(hwndDlg);
117 }
118 break;
119 }
120
121 return FALSE;
122}
unsigned char BOOLEAN
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define IDC_HIBERNATEFILE
Definition: resource.h:105
#define IDC_FREESPACE
Definition: resource.h:106
#define IDC_TOLESSFREESPACE
Definition: resource.h:108
#define IDC_SPACEFORHIBERNATEFILE
Definition: resource.h:107
#define MAX_PATH
Definition: compat.h:34
#define CALLBACK
Definition: compat.h:35
BOOL NTAPI GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
Definition: heapmem.c:1272
INT_PTR Hib_SaveData(HWND hwndDlg)
Definition: hibernate.c:73
static VOID Hib_InitDialog(HWND hwndDlg)
Definition: hibernate.c:15
INT_PTR CALLBACK HibernateDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: hibernate.c:90
unsigned int UINT
Definition: ndis.h:50
@ SystemReserveHiberFile
Definition: ntpoapi.h:77
#define LOWORD(l)
Definition: pedump.c:82
#define BOOLEAN
Definition: pedump.c:73
BOOLEAN WINAPI GetPwrCapabilities(PSYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities)
Definition: powrprof.c:358
NTSTATUS WINAPI CallNtPowerInformation(POWER_INFORMATION_LEVEL InformationLevel, PVOID lpInputBuffer, ULONG nInputBufferSize, PVOID lpOutputBuffer, ULONG nOutputBufferSize)
Definition: powrprof.c:59
#define PropSheet_Changed(d, w)
Definition: prsht.h:344
#define PSN_APPLY
Definition: prsht.h:117
#define WM_NOTIFY
Definition: richedit.h:61
#define STATUS_SUCCESS
Definition: shellext.h:65
#define StrFormatByteSize
Definition: shlwapi.h:1566
#define _countof(array)
Definition: sndvol32.h:70
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
Definition: inflate.c:139
int32_t INT_PTR
Definition: typedefs.h:64
#define HIWORD(l)
Definition: typedefs.h:247
#define GetWindowsDirectory
Definition: winbase.h:3857
#define GetDiskFreeSpaceEx
Definition: winbase.h:3808
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
#define BST_UNCHECKED
Definition: winuser.h:199
#define WM_COMMAND
Definition: winuser.h:1740
#define WM_INITDIALOG
Definition: winuser.h:1739
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
HWND WINAPI GetParent(_In_ HWND)
#define BN_CLICKED
Definition: winuser.h:1925
#define SetDlgItemText
Definition: winuser.h:5849
#define BST_CHECKED
Definition: winuser.h:197
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192