ReactOS  0.4.15-dev-1171-gab82533
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 
14 static VOID
16 {
17  SYSTEM_POWER_CAPABILITIES PowerCaps;
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));
51  SetDlgItemText(hwndDlg, IDC_SPACEFORHIBERNATEFILE, 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 
72 INT_PTR
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,
92  WPARAM wParam,
93  LPARAM lParam)
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  {
104  case IDC_HIBERNATEFILE:
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 }
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
#define TRUE
Definition: types.h:120
#define IDC_TOLESSFREESPACE
Definition: resource.h:108
#define CALLBACK
Definition: compat.h:35
BOOLEAN WINAPI GetPwrCapabilities(PSYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities)
Definition: powrprof.c:358
#define IDC_SPACEFORHIBERNATEFILE
Definition: resource.h:107
UINT_PTR WPARAM
Definition: windef.h:207
#define PSN_APPLY
Definition: prsht.h:117
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
int32_t INT_PTR
Definition: typedefs.h:64
WPARAM wParam
Definition: combotst.c:138
CHAR * LPTSTR
Definition: xmlstorage.h:192
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
#define FALSE
Definition: types.h:117
#define StrFormatByteSize
Definition: shlwapi.h:1566
NTSTATUS WINAPI CallNtPowerInformation(POWER_INFORMATION_LEVEL InformationLevel, PVOID lpInputBuffer, ULONG nInputBufferSize, PVOID lpOutputBuffer, ULONG nOutputBufferSize)
Definition: powrprof.c:59
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
char TCHAR
Definition: xmlstorage.h:189
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define PropSheet_Changed(d, w)
Definition: prsht.h:344
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
#define BN_CLICKED
Definition: winuser.h:1907
#define IDC_HIBERNATEFILE
Definition: resource.h:105
#define SetDlgItemText
Definition: winuser.h:5824
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
#define WM_COMMAND
Definition: winuser.h:1722
Definition: inflate.c:139
#define BST_UNCHECKED
Definition: winuser.h:199
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define GetDiskFreeSpaceEx
Definition: winbase.h:3648
HWND WINAPI GetParent(_In_ HWND)
unsigned int UINT
Definition: ndis.h:50
#define BST_CHECKED
Definition: winuser.h:197
#define BOOLEAN
Definition: pedump.c:73
INT_PTR Hib_SaveData(HWND hwndDlg)
Definition: hibernate.c:73
#define IDC_FREESPACE
Definition: resource.h:106
#define HIWORD(l)
Definition: typedefs.h:247
BOOL NTAPI GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
Definition: heapmem.c:1272
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define GetWindowsDirectory
Definition: winbase.h:3697
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define WM_NOTIFY
Definition: richedit.h:61