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 BOOLEAN Pos_InitData(); 15 void Adv_InitDialog(); 16 17 18 static VOID 19 Hib_InitDialog(HWND hwndDlg) 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, 30 IDC_HIBERNATEFILE, 31 PowerCaps.HiberFilePresent ? BST_CHECKED : BST_UNCHECKED); 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 { 58 EnableWindow(GetDlgItem(hwndDlg, IDC_HIBERNATEFILE), FALSE); 59 ShowWindow(GetDlgItem(hwndDlg, IDC_TOLESSFREESPACE), TRUE); 60 } 61 else 62 { 63 ShowWindow(GetDlgItem(hwndDlg, IDC_TOLESSFREESPACE), FALSE); 64 EnableWindow(GetDlgItem(hwndDlg, IDC_HIBERNATEFILE), TRUE); 65 } 66 } 67 } 68 69 INT_PTR 70 Hib_SaveData(HWND hwndDlg) 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(); 79 Adv_InitDialog(); 80 Hib_InitDialog(hwndDlg); 81 return TRUE; 82 } 83 84 return FALSE; 85 } 86 87 /* Property page dialog callback */ 88 INT_PTR CALLBACK 89 HibernateDlgProc(HWND hwndDlg, 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 100 case WM_COMMAND: 101 switch (LOWORD(wParam)) 102 { 103 case IDC_HIBERNATEFILE: 104 if (HIWORD(wParam) == BN_CLICKED) 105 { 106 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 107 } 108 break; 109 } 110 break; 111 112 case WM_NOTIFY: 113 { 114 LPNMHDR lpnm = (LPNMHDR)lParam; 115 if (lpnm->code == (UINT)PSN_APPLY) 116 { 117 return Hib_SaveData(hwndDlg); 118 } 119 } 120 } 121 122 return FALSE; 123 } 124