ReactOS  0.4.13-dev-66-gc714b7f
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 
15 void Adv_InitDialog();
16 
17 
18 static VOID
20 {
21  SYSTEM_POWER_CAPABILITIES PowerCaps;
22  MEMORYSTATUSEX msex;
23  TCHAR szTemp[MAX_PATH];
24  LPTSTR lpRoot;
25  ULARGE_INTEGER FreeBytesAvailable, TotalNumberOfBytes, TotalNumberOfFreeBytes;
26 
27  if (GetPwrCapabilities(&PowerCaps))
28  {
29  CheckDlgButton(hwndDlg,
32 
33  msex.dwLength = sizeof(msex);
34  if (!GlobalMemoryStatusEx(&msex))
35  {
36  return; // FIXME
37  }
38 
39  if (GetWindowsDirectory(szTemp,MAX_PATH))
40  lpRoot = szTemp;
41  else
42  lpRoot = NULL;
43 
44  // Get available space and size of selected volume.
45  if (!GetDiskFreeSpaceEx(lpRoot, &FreeBytesAvailable, &TotalNumberOfBytes, &TotalNumberOfFreeBytes))
46  TotalNumberOfFreeBytes.QuadPart = 0;
47 
48  // Print the free available space into selected volume.
49  StrFormatByteSize(TotalNumberOfFreeBytes.QuadPart, szTemp, _countof(szTemp));
50  SetDlgItemText(hwndDlg, IDC_FREESPACE, szTemp);
51 
52  // Print the amount of space required for hibernation.
53  StrFormatByteSize(msex.ullTotalPhys, szTemp, _countof(szTemp));
54  SetDlgItemText(hwndDlg, IDC_SPACEFORHIBERNATEFILE, szTemp);
55 
56  if (TotalNumberOfFreeBytes.QuadPart < msex.ullTotalPhys && !PowerCaps.HiberFilePresent)
57  {
60  }
61  else
62  {
65  }
66  }
67 }
68 
69 INT_PTR
71 {
72  BOOLEAN bHibernate;
73 
74  bHibernate = (BOOLEAN)(IsDlgButtonChecked(hwndDlg, IDC_HIBERNATEFILE) == BST_CHECKED);
75 
76  if (CallNtPowerInformation(SystemReserveHiberFile,&bHibernate, sizeof(bHibernate), NULL, 0) == STATUS_SUCCESS)
77  {
78  Pos_InitData();
80  Hib_InitDialog(hwndDlg);
81  return TRUE;
82  }
83 
84  return FALSE;
85 }
86 
87 /* Property page dialog callback */
90  UINT uMsg,
91  WPARAM wParam,
92  LPARAM lParam)
93 {
94  switch(uMsg)
95  {
96  case WM_INITDIALOG:
97  Hib_InitDialog(hwndDlg);
98  return TRUE;
99  case WM_COMMAND:
100  switch(LOWORD(wParam))
101  {
102  case IDC_HIBERNATEFILE:
103  if (HIWORD(wParam) == BN_CLICKED)
104  {
105  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
106  }
107  }
108  break;
109  case WM_NOTIFY:
110  {
111  LPNMHDR lpnm = (LPNMHDR)lParam;
112  if (lpnm->code == (UINT)PSN_APPLY)
113  {
114  return Hib_SaveData(hwndDlg);
115  }
116  }
117  }
118  return FALSE;
119 }
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:105
#define CALLBACK
Definition: compat.h:27
BOOLEAN WINAPI GetPwrCapabilities(PSYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities)
Definition: powrprof.c:358
#define IDC_SPACEFORHIBERNATEFILE
Definition: resource.h:104
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
struct tagNMHDR * LPNMHDR
UINT code
Definition: winuser.h:3112
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
BOOLEAN Pos_InitData()
#define MAX_PATH
Definition: compat.h:26
#define BN_CLICKED
Definition: winuser.h:1886
#define IDC_HIBERNATEFILE
Definition: resource.h:102
#define SetDlgItemText
Definition: winuser.h:5715
static VOID Hib_InitDialog(HWND hwndDlg)
Definition: hibernate.c:19
INT_PTR CALLBACK HibernateDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: hibernate.c:89
#define WM_COMMAND
Definition: winuser.h:1716
#define BST_UNCHECKED
Definition: winuser.h:199
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define GetDiskFreeSpaceEx
Definition: winbase.h:3622
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:70
#define IDC_FREESPACE
Definition: resource.h:103
#define HIWORD(l)
Definition: typedefs.h:246
void Adv_InitDialog()
BOOL NTAPI GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
Definition: heapmem.c:1272
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define GetWindowsDirectory
Definition: winbase.h:3671
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define WM_NOTIFY
Definition: richedit.h:61