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