ReactOS  0.4.14-dev-41-g31d7680
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 
23  if (GetPwrCapabilities(&PowerCaps))
24  {
25  CheckDlgButton(hwndDlg,
28 
29  msex.dwLength = sizeof(msex);
30  if (!GlobalMemoryStatusEx(&msex))
31  {
32  return; // FIXME
33  }
34 
35  if (GetWindowsDirectory(szTemp,MAX_PATH))
36  lpRoot = szTemp;
37  else
38  lpRoot = NULL;
39 
40  // Get available space and size of selected volume.
41  if (!GetDiskFreeSpaceEx(lpRoot, &FreeBytesAvailable, &TotalNumberOfBytes, &TotalNumberOfFreeBytes))
42  TotalNumberOfFreeBytes.QuadPart = 0;
43 
44  // Print the free available space into selected volume.
45  StrFormatByteSize(TotalNumberOfFreeBytes.QuadPart, szTemp, _countof(szTemp));
46  SetDlgItemText(hwndDlg, IDC_FREESPACE, szTemp);
47 
48  // Print the amount of space required for hibernation.
49  StrFormatByteSize(msex.ullTotalPhys, szTemp, _countof(szTemp));
50  SetDlgItemText(hwndDlg, IDC_SPACEFORHIBERNATEFILE, szTemp);
51 
52  if (TotalNumberOfFreeBytes.QuadPart < msex.ullTotalPhys && !PowerCaps.HiberFilePresent)
53  {
56  }
57  else
58  {
61  }
62  }
63 }
64 
65 INT_PTR
67 {
68  BOOLEAN bHibernate;
69 
70  bHibernate = (BOOLEAN)(IsDlgButtonChecked(hwndDlg, IDC_HIBERNATEFILE) == BST_CHECKED);
71 
72  if (CallNtPowerInformation(SystemReserveHiberFile, &bHibernate, sizeof(bHibernate), NULL, 0) == STATUS_SUCCESS)
73  {
74  Hib_InitDialog(hwndDlg);
75  return TRUE;
76  }
77 
78  return FALSE;
79 }
80 
81 /* Property page dialog callback */
84  UINT uMsg,
85  WPARAM wParam,
86  LPARAM lParam)
87 {
88  switch (uMsg)
89  {
90  case WM_INITDIALOG:
91  Hib_InitDialog(hwndDlg);
92  return TRUE;
93 
94  case WM_COMMAND:
95  switch (LOWORD(wParam))
96  {
97  case IDC_HIBERNATEFILE:
98  if (HIWORD(wParam) == BN_CLICKED)
99  {
100  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
101  }
102  break;
103  }
104  break;
105 
106  case WM_NOTIFY:
107  if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY)
108  {
109  return Hib_SaveData(hwndDlg);
110  }
111  break;
112  }
113 
114  return FALSE;
115 }
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
#define TRUE
Definition: types.h:120
#define _countof(array)
Definition: fontsub.cpp:30
#define IDC_TOLESSFREESPACE
Definition: resource.h:107
#define CALLBACK
Definition: compat.h:27
BOOLEAN WINAPI GetPwrCapabilities(PSYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities)
Definition: powrprof.c:358
#define IDC_SPACEFORHIBERNATEFILE
Definition: resource.h:106
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:62
WPARAM wParam
Definition: combotst.c:138
CHAR * LPTSTR
Definition: xmlstorage.h:192
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
#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:326
#define MAX_PATH
Definition: compat.h:26
#define BN_CLICKED
Definition: winuser.h:1907
#define IDC_HIBERNATEFILE
Definition: resource.h:104
#define SetDlgItemText
Definition: winuser.h:5750
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:83
#define WM_COMMAND
Definition: winuser.h:1722
#define BST_UNCHECKED
Definition: winuser.h:199
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define GetDiskFreeSpaceEx
Definition: winbase.h:3625
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:66
#define IDC_FREESPACE
Definition: resource.h:105
#define HIWORD(l)
Definition: typedefs.h:246
BOOL NTAPI GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
Definition: heapmem.c:1272
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define GetWindowsDirectory
Definition: winbase.h:3674
#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