PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/reactos/dll/cpl/sysdm/virtmem.c

https://gitlab.com/dj-tech/reactos
C | 735 lines | 580 code | 120 blank | 35 comment | 93 complexity | 59f706385a897a2ecbbb7429e1d94d71 MD5 | raw file
  1. /*
  2. * PROJECT: ReactOS system properties, control panel applet
  3. * LICENSE: GPL - See COPYING in the top level directory
  4. * FILE: dll/cpl/sysdm/virtmem.c
  5. * PURPOSE: Virtual memory control dialog
  6. * COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
  7. *
  8. */
  9. #include "precomp.h"
  10. static BOOL OnSelChange(HWND hwndDlg, PVIRTMEM pVirtMem);
  11. static LPCTSTR lpKey = _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management");
  12. static BOOL
  13. ReadPageFileSettings(PVIRTMEM pVirtMem)
  14. {
  15. HKEY hkey = NULL;
  16. DWORD dwType;
  17. DWORD dwDataSize;
  18. BOOL bRet = FALSE;
  19. if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  20. lpKey,
  21. 0,
  22. NULL,
  23. REG_OPTION_NON_VOLATILE,
  24. KEY_QUERY_VALUE,
  25. NULL,
  26. &hkey,
  27. NULL) == ERROR_SUCCESS)
  28. {
  29. if (RegQueryValueEx(hkey,
  30. _T("PagingFiles"),
  31. NULL,
  32. &dwType,
  33. NULL,
  34. &dwDataSize) == ERROR_SUCCESS)
  35. {
  36. pVirtMem->szPagingFiles = (LPTSTR)HeapAlloc(GetProcessHeap(),
  37. 0,
  38. dwDataSize);
  39. if (pVirtMem->szPagingFiles != NULL)
  40. {
  41. ZeroMemory(pVirtMem->szPagingFiles,
  42. dwDataSize);
  43. if (RegQueryValueEx(hkey,
  44. _T("PagingFiles"),
  45. NULL,
  46. &dwType,
  47. (PBYTE)pVirtMem->szPagingFiles,
  48. &dwDataSize) == ERROR_SUCCESS)
  49. {
  50. bRet = TRUE;
  51. }
  52. }
  53. }
  54. }
  55. if (!bRet)
  56. ShowLastWin32Error(pVirtMem->hSelf);
  57. if (hkey != NULL)
  58. RegCloseKey(hkey);
  59. return bRet;
  60. }
  61. static VOID
  62. GetPageFileSizes(LPTSTR lpPageFiles,
  63. LPINT lpInitialSize,
  64. LPINT lpMaximumSize)
  65. {
  66. INT i = 0;
  67. *lpInitialSize = -1;
  68. *lpMaximumSize = -1;
  69. while (*lpPageFiles != _T('\0'))
  70. {
  71. if (*lpPageFiles == _T(' '))
  72. {
  73. lpPageFiles++;
  74. switch (i)
  75. {
  76. case 0:
  77. *lpInitialSize = (INT)_ttoi(lpPageFiles);
  78. i = 1;
  79. break;
  80. case 1:
  81. *lpMaximumSize = (INT)_ttoi(lpPageFiles);
  82. return;
  83. }
  84. }
  85. lpPageFiles++;
  86. }
  87. }
  88. static VOID
  89. ParseMemSettings(PVIRTMEM pVirtMem)
  90. {
  91. TCHAR szDrives[1024]; // All drives
  92. LPTSTR DrivePtr = szDrives;
  93. TCHAR szDrive[3]; // Single drive
  94. TCHAR szVolume[MAX_PATH + 1];
  95. INT MinSize;
  96. INT MaxSize;
  97. INT DriveLen;
  98. INT PgCnt = 0;
  99. INT Len;
  100. DriveLen = GetLogicalDriveStrings(1023,
  101. szDrives);
  102. while (DriveLen != 0)
  103. {
  104. Len = lstrlen(DrivePtr) + 1;
  105. DriveLen -= Len;
  106. DrivePtr = _tcsupr(DrivePtr);
  107. /* Copy the 'X:' portion */
  108. lstrcpyn(szDrive, DrivePtr, sizeof(szDrive) / sizeof(TCHAR));
  109. if (GetDriveType(DrivePtr) == DRIVE_FIXED)
  110. {
  111. MinSize = -1;
  112. MaxSize = -1;
  113. /* Does drive match the one in the registry ? */
  114. if (!_tcsncmp(pVirtMem->szPagingFiles, szDrive, 2))
  115. {
  116. GetPageFileSizes(pVirtMem->szPagingFiles,
  117. &MinSize,
  118. &MaxSize);
  119. }
  120. pVirtMem->Pagefile[PgCnt].OldMinSize = MinSize;
  121. pVirtMem->Pagefile[PgCnt].OldMaxSize = MaxSize;
  122. pVirtMem->Pagefile[PgCnt].NewMinSize = MinSize;
  123. pVirtMem->Pagefile[PgCnt].NewMaxSize = MaxSize;
  124. pVirtMem->Pagefile[PgCnt].bUsed = TRUE;
  125. lstrcpy(pVirtMem->Pagefile[PgCnt].szDrive, szDrive);
  126. /* Get the volume label if there is one */
  127. if (GetVolumeInformation(DrivePtr,
  128. szVolume,
  129. MAX_PATH + 1,
  130. NULL,
  131. NULL,
  132. NULL,
  133. NULL,
  134. 0))
  135. {
  136. pVirtMem->Pagefile[PgCnt].pszVolume = HeapAlloc(GetProcessHeap(),
  137. 0,
  138. (_tcslen(szVolume) + 1) * sizeof(TCHAR));
  139. if (pVirtMem->Pagefile[PgCnt].pszVolume != NULL)
  140. _tcscpy(pVirtMem->Pagefile[PgCnt].pszVolume, szVolume);
  141. }
  142. PgCnt++;
  143. }
  144. DrivePtr += Len;
  145. }
  146. pVirtMem->Count = PgCnt;
  147. }
  148. static VOID
  149. WritePageFileSettings(PVIRTMEM pVirtMem)
  150. {
  151. HKEY hk = NULL;
  152. TCHAR szPagingFiles[2048];
  153. TCHAR szText[256];
  154. INT i, nPos = 0;
  155. BOOL bErr = TRUE;
  156. for (i = 0; i < pVirtMem->Count; ++i)
  157. {
  158. if (pVirtMem->Pagefile[i].bUsed &&
  159. pVirtMem->Pagefile[i].NewMinSize != -1 &&
  160. pVirtMem->Pagefile[i].NewMaxSize != -1)
  161. {
  162. _stprintf(szText,
  163. _T("%s\\pagefile.sys %i %i"),
  164. pVirtMem->Pagefile[i].szDrive,
  165. pVirtMem->Pagefile[i].NewMinSize,
  166. pVirtMem->Pagefile[i].NewMaxSize);
  167. /* Add it to our overall registry string */
  168. lstrcpy(szPagingFiles + nPos, szText);
  169. /* Record the position where the next string will start */
  170. nPos += (INT)lstrlen(szText) + 1;
  171. /* Add another NULL for REG_MULTI_SZ */
  172. szPagingFiles[nPos] = _T('\0');
  173. nPos++;
  174. }
  175. }
  176. if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  177. lpKey,
  178. 0,
  179. NULL,
  180. REG_OPTION_NON_VOLATILE,
  181. KEY_WRITE,
  182. NULL,
  183. &hk,
  184. NULL) == ERROR_SUCCESS)
  185. {
  186. if (RegSetValueEx(hk,
  187. _T("PagingFiles"),
  188. 0,
  189. REG_MULTI_SZ,
  190. (LPBYTE) szPagingFiles,
  191. (DWORD) nPos * sizeof(TCHAR)) == ERROR_SUCCESS)
  192. {
  193. bErr = FALSE;
  194. }
  195. RegCloseKey(hk);
  196. }
  197. if (bErr == FALSE)
  198. {
  199. /* Delete obsolete paging files on the next boot */
  200. for (i = 0; i < 26; i++)
  201. {
  202. if (pVirtMem->Pagefile[i].OldMinSize != -1 &&
  203. pVirtMem->Pagefile[i].NewMinSize == -1)
  204. {
  205. _stprintf(szText,
  206. _T("%s\\pagefile.sys"),
  207. pVirtMem->Pagefile[i].szDrive);
  208. MoveFileEx(szText, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
  209. }
  210. }
  211. }
  212. if (bErr)
  213. ShowLastWin32Error(pVirtMem->hSelf);
  214. }
  215. static VOID
  216. SetListBoxColumns(HWND hwndListBox)
  217. {
  218. RECT rect = {0, 0, 103, 0};
  219. MapDialogRect(hwndListBox, &rect);
  220. SendMessage(hwndListBox, LB_SETTABSTOPS, (WPARAM)1, (LPARAM)&rect.right);
  221. }
  222. static VOID
  223. OnNoPagingFile(PVIRTMEM pVirtMem)
  224. {
  225. /* Disable the page file custom size boxes */
  226. EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), FALSE);
  227. EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), FALSE);
  228. }
  229. static VOID
  230. OnSysManSize(PVIRTMEM pVirtMem)
  231. {
  232. /* Disable the page file custom size boxes */
  233. EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), FALSE);
  234. EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), FALSE);
  235. }
  236. static VOID
  237. OnCustom(PVIRTMEM pVirtMem)
  238. {
  239. /* Enable the page file custom size boxes */
  240. EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), TRUE);
  241. EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), TRUE);
  242. }
  243. static VOID
  244. InitPagefileList(PVIRTMEM pVirtMem)
  245. {
  246. TCHAR szDisplayString[256];
  247. TCHAR szSize[64];
  248. INT Index;
  249. INT i;
  250. for (i = 0; i < 26; i++)
  251. {
  252. if (pVirtMem->Pagefile[i].bUsed)
  253. {
  254. if ((pVirtMem->Pagefile[i].NewMinSize == -1) &&
  255. (pVirtMem->Pagefile[i].NewMaxSize == -1))
  256. {
  257. LoadString(hApplet,
  258. IDS_PAGEFILE_NONE,
  259. szSize,
  260. sizeof(szSize) / sizeof(szSize[0]));
  261. }
  262. else if ((pVirtMem->Pagefile[i].NewMinSize == 0) &&
  263. (pVirtMem->Pagefile[i].NewMaxSize == 0))
  264. {
  265. LoadString(hApplet,
  266. IDS_PAGEFILE_SYSTEM,
  267. szSize,
  268. sizeof(szSize) / sizeof(szSize[0]));
  269. }
  270. else
  271. {
  272. _stprintf(szSize, _T("%d - %d"),
  273. pVirtMem->Pagefile[i].NewMinSize,
  274. pVirtMem->Pagefile[i].NewMaxSize);
  275. }
  276. _stprintf(szDisplayString,
  277. _T("%s [%s]\t%s"),
  278. pVirtMem->Pagefile[i].szDrive,
  279. pVirtMem->Pagefile[i].pszVolume ? pVirtMem->Pagefile[i].pszVolume : _T(""),
  280. szSize);
  281. Index = SendMessage(pVirtMem->hListBox, LB_ADDSTRING, (WPARAM)0, (LPARAM)szDisplayString);
  282. SendMessage(pVirtMem->hListBox, LB_SETITEMDATA, Index, i);
  283. }
  284. }
  285. SendMessage(pVirtMem->hListBox, LB_SETCURSEL, (WPARAM)0, (LPARAM)0);
  286. OnSelChange(pVirtMem->hSelf, pVirtMem);
  287. }
  288. static VOID
  289. UpdatePagefileEntry(PVIRTMEM pVirtMem,
  290. INT ListIndex,
  291. INT DriveIndex)
  292. {
  293. TCHAR szDisplayString[256];
  294. TCHAR szSize[64];
  295. if ((pVirtMem->Pagefile[DriveIndex].NewMinSize == -1) &&
  296. (pVirtMem->Pagefile[DriveIndex].NewMaxSize == -1))
  297. {
  298. LoadString(hApplet,
  299. IDS_PAGEFILE_NONE,
  300. szSize,
  301. sizeof(szSize) / sizeof(szSize[0]));
  302. }
  303. else if ((pVirtMem->Pagefile[DriveIndex].NewMinSize == 0) &&
  304. (pVirtMem->Pagefile[DriveIndex].NewMaxSize == 0))
  305. {
  306. LoadString(hApplet,
  307. IDS_PAGEFILE_SYSTEM,
  308. szSize,
  309. sizeof(szSize) / sizeof(szSize[0]));
  310. }
  311. else
  312. {
  313. _stprintf(szSize,
  314. _T("%d - %d"),
  315. pVirtMem->Pagefile[DriveIndex].NewMinSize,
  316. pVirtMem->Pagefile[DriveIndex].NewMaxSize);
  317. }
  318. _stprintf(szDisplayString,
  319. _T("%s [%s]\t%s"),
  320. pVirtMem->Pagefile[DriveIndex].szDrive,
  321. pVirtMem->Pagefile[DriveIndex].pszVolume ? pVirtMem->Pagefile[DriveIndex].pszVolume : L"",
  322. szSize);
  323. SendMessage(pVirtMem->hListBox, LB_DELETESTRING, (WPARAM)ListIndex, 0);
  324. SendMessage(pVirtMem->hListBox, LB_INSERTSTRING, (WPARAM)ListIndex, (LPARAM)szDisplayString);
  325. SendMessage(pVirtMem->hListBox, LB_SETCURSEL, (WPARAM)ListIndex, 0);
  326. }
  327. static VOID
  328. OnSet(PVIRTMEM pVirtMem)
  329. {
  330. INT Index;
  331. UINT MinSize = -1;
  332. UINT MaxSize = -1;
  333. BOOL bTranslated;
  334. INT DriveIndex = 0;
  335. Index = (INT)SendDlgItemMessage(pVirtMem->hSelf,
  336. IDC_PAGEFILELIST,
  337. LB_GETCURSEL,
  338. 0,
  339. 0);
  340. if (Index >= 0 && Index < pVirtMem->Count)
  341. {
  342. DriveIndex = SendDlgItemMessage(pVirtMem->hSelf,
  343. IDC_PAGEFILELIST,
  344. LB_GETITEMDATA,
  345. 0,
  346. 0);
  347. /* Check if custom settings are checked */
  348. if (IsDlgButtonChecked(pVirtMem->hSelf,
  349. IDC_CUSTOM) == BST_CHECKED)
  350. {
  351. MinSize = GetDlgItemInt(pVirtMem->hSelf,
  352. IDC_INITIALSIZE,
  353. &bTranslated,
  354. FALSE);
  355. if (!bTranslated)
  356. {
  357. ResourceMessageBox(hApplet,
  358. NULL,
  359. MB_ICONWARNING | MB_OK,
  360. IDS_MESSAGEBOXTITLE,
  361. IDS_WARNINITIALSIZE);
  362. return;
  363. }
  364. MaxSize = GetDlgItemInt(pVirtMem->hSelf,
  365. IDC_MAXSIZE,
  366. &bTranslated,
  367. FALSE);
  368. if (!bTranslated)
  369. {
  370. ResourceMessageBox(hApplet,
  371. NULL,
  372. MB_ICONWARNING | MB_OK,
  373. IDS_MESSAGEBOXTITLE,
  374. IDS_WARNMAXIMUMSIZE);
  375. return;
  376. }
  377. /* Check the valid range of the minimum size */
  378. if (MinSize < 16 ||
  379. MinSize > pVirtMem->Pagefile[DriveIndex].FreeSize)
  380. {
  381. ResourceMessageBox(hApplet,
  382. NULL,
  383. MB_ICONWARNING | MB_OK,
  384. IDS_MESSAGEBOXTITLE,
  385. IDS_WARNINITIALRANGE);
  386. return;
  387. }
  388. /* Check the valid range of the maximum size */
  389. if (MaxSize < MinSize ||
  390. MaxSize > pVirtMem->Pagefile[DriveIndex].FreeSize ||
  391. MaxSize > 4095)
  392. {
  393. ResourceMessageBox(hApplet,
  394. NULL,
  395. MB_ICONWARNING | MB_OK,
  396. IDS_MESSAGEBOXTITLE,
  397. IDS_WARNMAXIMUMRANGE);
  398. return;
  399. }
  400. pVirtMem->Pagefile[DriveIndex].NewMinSize = MinSize;
  401. pVirtMem->Pagefile[DriveIndex].NewMaxSize = MaxSize;
  402. pVirtMem->Pagefile[DriveIndex].bUsed = TRUE;
  403. }
  404. else if (IsDlgButtonChecked(pVirtMem->hSelf,
  405. IDC_NOPAGEFILE) == BST_CHECKED)
  406. {
  407. /* No pagefile */
  408. pVirtMem->Pagefile[DriveIndex].NewMinSize = -1;
  409. pVirtMem->Pagefile[DriveIndex].NewMaxSize = -1;
  410. pVirtMem->Pagefile[DriveIndex].bUsed = TRUE;
  411. }
  412. else
  413. {
  414. /* System managed size*/
  415. pVirtMem->Pagefile[DriveIndex].NewMinSize = 0;
  416. pVirtMem->Pagefile[DriveIndex].NewMaxSize = 0;
  417. pVirtMem->Pagefile[DriveIndex].bUsed = TRUE;
  418. }
  419. /* Set the modified flag if min or max size has changed */
  420. if ((pVirtMem->Pagefile[DriveIndex].OldMinSize != pVirtMem->Pagefile[DriveIndex].NewMinSize) ||
  421. (pVirtMem->Pagefile[DriveIndex].OldMaxSize != pVirtMem->Pagefile[DriveIndex].NewMaxSize))
  422. pVirtMem->bModified = TRUE;
  423. UpdatePagefileEntry(pVirtMem, Index, DriveIndex);
  424. }
  425. }
  426. static BOOL
  427. OnSelChange(HWND hwndDlg, PVIRTMEM pVirtMem)
  428. {
  429. TCHAR szBuffer[64];
  430. MEMORYSTATUSEX MemoryStatus;
  431. ULARGE_INTEGER FreeDiskSpace;
  432. UINT /*i,*/ FreeMemMb /*, PageFileSizeMb*/;
  433. INT Index;
  434. Index = (INT)SendDlgItemMessage(hwndDlg,
  435. IDC_PAGEFILELIST,
  436. LB_GETCURSEL,
  437. 0,
  438. 0);
  439. if (Index >= 0 && Index < pVirtMem->Count)
  440. {
  441. /* Set drive letter */
  442. SetDlgItemText(hwndDlg, IDC_DRIVE,
  443. pVirtMem->Pagefile[Index].szDrive);
  444. /* Set available disk space */
  445. if (GetDiskFreeSpaceEx(pVirtMem->Pagefile[Index].szDrive,
  446. NULL, NULL, &FreeDiskSpace))
  447. {
  448. pVirtMem->Pagefile[Index].FreeSize = (UINT)(FreeDiskSpace.QuadPart / (1024 * 1024));
  449. _stprintf(szBuffer, _T("%u MB"), pVirtMem->Pagefile[Index].FreeSize);
  450. SetDlgItemText(hwndDlg, IDC_SPACEAVAIL, szBuffer);
  451. }
  452. if (pVirtMem->Pagefile[Index].NewMinSize == -1 &&
  453. pVirtMem->Pagefile[Index].NewMaxSize == -1)
  454. {
  455. /* No pagefile */
  456. EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), FALSE);
  457. EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), FALSE);
  458. CheckDlgButton(pVirtMem->hSelf, IDC_NOPAGEFILE, BST_CHECKED);
  459. }
  460. else if (pVirtMem->Pagefile[Index].NewMinSize == 0 &&
  461. pVirtMem->Pagefile[Index].NewMaxSize == 0)
  462. {
  463. /* System managed size*/
  464. EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), FALSE);
  465. EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), FALSE);
  466. CheckDlgButton(pVirtMem->hSelf, IDC_SYSMANSIZE, BST_CHECKED);
  467. }
  468. else
  469. {
  470. /* Custom size */
  471. /* Enable and fill the custom values */
  472. EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), TRUE);
  473. EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), TRUE);
  474. SetDlgItemInt(pVirtMem->hSelf,
  475. IDC_INITIALSIZE,
  476. pVirtMem->Pagefile[Index].NewMinSize,
  477. FALSE);
  478. SetDlgItemInt(pVirtMem->hSelf,
  479. IDC_MAXSIZE,
  480. pVirtMem->Pagefile[Index].NewMaxSize,
  481. FALSE);
  482. CheckDlgButton(pVirtMem->hSelf,
  483. IDC_CUSTOM,
  484. BST_CHECKED);
  485. }
  486. /* Set minimum pagefile size */
  487. SetDlgItemText(hwndDlg, IDC_MINIMUM, _T("16 MB"));
  488. /* Set recommended pagefile size */
  489. MemoryStatus.dwLength = sizeof(MEMORYSTATUSEX);
  490. if (GlobalMemoryStatusEx(&MemoryStatus))
  491. {
  492. FreeMemMb = (UINT)(MemoryStatus.ullTotalPhys / (1024 * 1024));
  493. _stprintf(szBuffer, _T("%u MB"), FreeMemMb + (FreeMemMb / 2));
  494. SetDlgItemText(hwndDlg, IDC_RECOMMENDED, szBuffer);
  495. }
  496. /* Set current pagefile size */
  497. #if 0
  498. PageFileSizeMb = 0;
  499. for (i = 0; i < 26; i++)
  500. {
  501. PageFileSizeMb += pVirtMem->Pagefile[i].InitialSize;
  502. }
  503. _stprintf(szBuffer, _T("%u MB"), PageFileSizeMb);
  504. SetDlgItemText(hwndDlg, IDC_CURRENT, szBuffer);
  505. #endif
  506. }
  507. return TRUE;
  508. }
  509. static VOID
  510. OnOk(PVIRTMEM pVirtMem)
  511. {
  512. if (pVirtMem->bModified == TRUE)
  513. {
  514. ResourceMessageBox(hApplet,
  515. NULL,
  516. MB_ICONINFORMATION | MB_OK,
  517. IDS_MESSAGEBOXTITLE,
  518. IDS_INFOREBOOT);
  519. WritePageFileSettings(pVirtMem);
  520. }
  521. }
  522. static VOID
  523. OnInitDialog(HWND hwnd, PVIRTMEM pVirtMem)
  524. {
  525. INT i;
  526. pVirtMem->hSelf = hwnd;
  527. pVirtMem->hListBox = GetDlgItem(hwnd, IDC_PAGEFILELIST);
  528. pVirtMem->bModified = FALSE;
  529. SetListBoxColumns(pVirtMem->hListBox);
  530. for (i = 0; i < 26; i++)
  531. {
  532. pVirtMem->Pagefile[i].bUsed = FALSE;
  533. pVirtMem->Pagefile[i].OldMinSize = -1;
  534. pVirtMem->Pagefile[i].OldMaxSize = -1;
  535. pVirtMem->Pagefile[i].NewMinSize = -1;
  536. pVirtMem->Pagefile[i].NewMaxSize = -1;
  537. }
  538. /* Load the pagefile systems from the reg */
  539. ReadPageFileSettings(pVirtMem);
  540. /* Parse our settings and set up dialog */
  541. ParseMemSettings(pVirtMem);
  542. InitPagefileList(pVirtMem);
  543. }
  544. static VOID
  545. OnDestroy(PVIRTMEM pVirtMem)
  546. {
  547. INT i;
  548. for (i = 0; i < 26; i++)
  549. {
  550. if (pVirtMem->Pagefile[i].pszVolume != NULL)
  551. HeapFree(GetProcessHeap(), 0, pVirtMem->Pagefile[i].pszVolume);
  552. }
  553. if (pVirtMem->szPagingFiles)
  554. HeapFree(GetProcessHeap(), 0, pVirtMem->szPagingFiles);
  555. HeapFree(GetProcessHeap(), 0, pVirtMem);
  556. }
  557. INT_PTR CALLBACK
  558. VirtMemDlgProc(HWND hwndDlg,
  559. UINT uMsg,
  560. WPARAM wParam,
  561. LPARAM lParam)
  562. {
  563. PVIRTMEM pVirtMem;
  564. UNREFERENCED_PARAMETER(lParam);
  565. pVirtMem = (PVIRTMEM)GetWindowLongPtr(hwndDlg, DWLP_USER);
  566. switch (uMsg)
  567. {
  568. case WM_INITDIALOG:
  569. pVirtMem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(VIRTMEM));
  570. if (pVirtMem == NULL)
  571. {
  572. EndDialog(hwndDlg, 0);
  573. return FALSE;
  574. }
  575. SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pVirtMem);
  576. OnInitDialog(hwndDlg, pVirtMem);
  577. break;
  578. case WM_DESTROY:
  579. OnDestroy(pVirtMem);
  580. break;
  581. case WM_COMMAND:
  582. switch (LOWORD(wParam))
  583. {
  584. case IDCANCEL:
  585. EndDialog(hwndDlg, 0);
  586. return TRUE;
  587. case IDOK:
  588. OnOk(pVirtMem);
  589. EndDialog(hwndDlg, pVirtMem->bModified);
  590. return TRUE;
  591. case IDC_NOPAGEFILE:
  592. OnNoPagingFile(pVirtMem);
  593. return TRUE;
  594. case IDC_SYSMANSIZE:
  595. OnSysManSize(pVirtMem);
  596. return TRUE;
  597. case IDC_CUSTOM:
  598. OnCustom(pVirtMem);
  599. return TRUE;
  600. case IDC_SET:
  601. OnSet(pVirtMem);
  602. return TRUE;
  603. case IDC_PAGEFILELIST:
  604. switch (HIWORD(wParam))
  605. {
  606. case LBN_SELCHANGE:
  607. OnSelChange(hwndDlg, pVirtMem);
  608. return TRUE;
  609. }
  610. break;
  611. }
  612. break;
  613. }
  614. return FALSE;
  615. }