TCHAR szDrives[1024]; // All drives
LPTSTR DrivePtr = szDrives;
TCHAR szDrive[3]; // Single drive
- TCHAR szVolume[MAX_PATH];
- TCHAR *szDisplayString;
- INT InitialSize = 0;
- INT MaximumSize = 0;
+ TCHAR szVolume[MAX_PATH + 1];
+ INT InitialSize;
+ INT MaximumSize;
INT DriveLen;
INT PgCnt = 0;
+ INT Len;
DriveLen = GetLogicalDriveStrings(1023,
szDrives);
- szDisplayString = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (MAX_PATH * 2 + 69) * sizeof(TCHAR));
- if (szDisplayString == NULL)
- return;
-
while (DriveLen != 0)
{
- INT Len;
-
Len = lstrlen(DrivePtr) + 1;
DriveLen -= Len;
if (GetDriveType(DrivePtr) == DRIVE_FIXED)
{
+ InitialSize = -1;
+ MaximumSize = -1;
+
/* Does drive match the one in the registry ? */
if (!_tcsncmp(pVirtMem->szPagingFiles, szDrive, 2))
{
- /* FIXME: We only check the first available pagefile in the reg */
GetPageFileSizes(pVirtMem->szPagingFiles,
&InitialSize,
&MaximumSize);
-
- pVirtMem->Pagefile[PgCnt].InitialSize = InitialSize;
- pVirtMem->Pagefile[PgCnt].MaximumSize = MaximumSize;
- pVirtMem->Pagefile[PgCnt].bUsed = TRUE;
- lstrcpy(pVirtMem->Pagefile[PgCnt].szDrive, szDrive);
- }
- else
- {
- pVirtMem->Pagefile[PgCnt].InitialSize = 0;
- pVirtMem->Pagefile[PgCnt].MaximumSize = 0;
- pVirtMem->Pagefile[PgCnt].bUsed = FALSE;
- lstrcpy(pVirtMem->Pagefile[PgCnt].szDrive, szDrive);
}
- _tcscpy(szDisplayString, szDrive);
- _tcscat(szDisplayString, _T("\t"));
+ pVirtMem->Pagefile[PgCnt].InitialSize = InitialSize;
+ pVirtMem->Pagefile[PgCnt].MaximumSize = MaximumSize;
+ pVirtMem->Pagefile[PgCnt].bUsed = TRUE;
+ lstrcpy(pVirtMem->Pagefile[PgCnt].szDrive, szDrive);
- /* Set a volume label if there is one */
+
+ /* Get the volume label if there is one */
if (GetVolumeInformation(DrivePtr,
szVolume,
- 255,
+ MAX_PATH + 1,
NULL,
NULL,
NULL,
NULL,
0))
{
- if (szVolume[0] != _T('\0'))
- {
- TCHAR szVol[MAX_PATH + 2];
- _stprintf(szVol, _T("[%s]"), szVolume);
- _tcscat(szDisplayString, szVol);
- }
- }
-
- if ((InitialSize != 0) || (MaximumSize != 0))
- {
- TCHAR szSize[64];
-
- _stprintf(szSize, _T("%i - %i"), InitialSize, MaximumSize);
- _tcscat(szDisplayString, _T("\t"));
- _tcscat(szDisplayString, szSize);
+ pVirtMem->Pagefile[PgCnt].pszVolume = HeapAlloc(GetProcessHeap(),
+ 0,
+ (_tcslen(szVolume) + 1) * sizeof(TCHAR));
+ if (pVirtMem->Pagefile[PgCnt].pszVolume != NULL)
+ _tcscpy(pVirtMem->Pagefile[PgCnt].pszVolume, szVolume);
}
- SendMessage(pVirtMem->hListBox, LB_ADDSTRING, (WPARAM)0, (LPARAM)szDisplayString);
PgCnt++;
}
DrivePtr += Len;
}
- SendMessage(pVirtMem->hListBox, LB_SETCURSEL, (WPARAM)0, (LPARAM)0);
- HeapFree(GetProcessHeap(), 0, szDisplayString);
pVirtMem->Count = PgCnt;
- OnSelChange(pVirtMem->hSelf, pVirtMem);
}
for (i = 0; i < pVirtMem->Count; ++i)
{
- if (pVirtMem->Pagefile[i].bUsed)
+ if (pVirtMem->Pagefile[i].bUsed &&
+ pVirtMem->Pagefile[i].InitialSize != -1 &&
+ pVirtMem->Pagefile[i].MaximumSize != -1)
{
- _stprintf(szText, _T("%s\\pagefile.sys %i %i"),
+ _stprintf(szText,
+ _T("%s\\pagefile.sys %i %i"),
pVirtMem->Pagefile[i].szDrive,
pVirtMem->Pagefile[i].InitialSize,
pVirtMem->Pagefile[i].MaximumSize);
static VOID
SetListBoxColumns(HWND hwndListBox)
{
- const INT tabs[2] = {30, 120};
+ RECT rect = {0, 0, 103, 0};
+ MapDialogRect(hwndListBox, &rect);
- SendMessage(hwndListBox, LB_SETTABSTOPS, (WPARAM)2, (LPARAM)&tabs[0]);
+ SendMessage(hwndListBox, LB_SETTABSTOPS, (WPARAM)1, (LPARAM)&rect.right);
}
}
+static VOID
+InitPagefileList(PVIRTMEM pVirtMem)
+{
+ TCHAR szDisplayString[256];
+ TCHAR szSize[64];
+ INT Index;
+ INT i;
+
+ for (i = 0; i < 26; i++)
+ {
+ if (pVirtMem->Pagefile[i].bUsed)
+ {
+ if ((pVirtMem->Pagefile[i].InitialSize == -1) &&
+ (pVirtMem->Pagefile[i].MaximumSize == -1))
+ {
+ LoadString(hApplet,
+ IDS_PAGEFILE_NONE,
+ szSize,
+ sizeof(szSize) / sizeof(szSize[0]));
+ }
+ else if ((pVirtMem->Pagefile[i].InitialSize == 0) &&
+ (pVirtMem->Pagefile[i].MaximumSize == 0))
+ {
+ LoadString(hApplet,
+ IDS_PAGEFILE_SYSTEM,
+ szSize,
+ sizeof(szSize) / sizeof(szSize[0]));
+ }
+ else
+ {
+ _stprintf(szSize, _T("%d - %d"),
+ pVirtMem->Pagefile[i].InitialSize,
+ pVirtMem->Pagefile[i].MaximumSize);
+ }
+
+ _stprintf(szDisplayString,
+ _T("%s [%s]\t%s"),
+ pVirtMem->Pagefile[i].szDrive,
+ pVirtMem->Pagefile[i].pszVolume ? pVirtMem->Pagefile[i].pszVolume : _T(""),
+ szSize);
+
+ Index = SendMessage(pVirtMem->hListBox, LB_ADDSTRING, (WPARAM)0, (LPARAM)szDisplayString);
+ SendMessage(pVirtMem->hListBox, LB_SETITEMDATA, Index, i);
+ }
+ }
+
+ SendMessage(pVirtMem->hListBox, LB_SETCURSEL, (WPARAM)0, (LPARAM)0);
+
+ OnSelChange(pVirtMem->hSelf, pVirtMem);
+}
+
+
+static VOID
+UpdatePagefileEntry(PVIRTMEM pVirtMem,
+ INT ListIndex,
+ INT DriveIndex)
+{
+ TCHAR szDisplayString[256];
+ TCHAR szSize[64];
+
+ if ((pVirtMem->Pagefile[DriveIndex].InitialSize == -1) &&
+ (pVirtMem->Pagefile[DriveIndex].MaximumSize == -1))
+ {
+ LoadString(hApplet,
+ IDS_PAGEFILE_NONE,
+ szSize,
+ sizeof(szSize) / sizeof(szSize[0]));
+ }
+ else if ((pVirtMem->Pagefile[DriveIndex].InitialSize == 0) &&
+ (pVirtMem->Pagefile[DriveIndex].MaximumSize == 0))
+ {
+ LoadString(hApplet,
+ IDS_PAGEFILE_SYSTEM,
+ szSize,
+ sizeof(szSize) / sizeof(szSize[0]));
+ }
+ else
+ {
+ _stprintf(szSize,
+ _T("%d - %d"),
+ pVirtMem->Pagefile[DriveIndex].InitialSize,
+ pVirtMem->Pagefile[DriveIndex].MaximumSize);
+ }
+
+ _stprintf(szDisplayString,
+ _T("%s [%s]\t%s"),
+ pVirtMem->Pagefile[DriveIndex].szDrive,
+ pVirtMem->Pagefile[DriveIndex].pszVolume ? pVirtMem->Pagefile[DriveIndex].pszVolume : L"",
+ szSize);
+
+ SendMessage(pVirtMem->hListBox, LB_DELETESTRING, (WPARAM)ListIndex, 0);
+ SendMessage(pVirtMem->hListBox, LB_INSERTSTRING, (WPARAM)ListIndex, (LPARAM)szDisplayString);
+ SendMessage(pVirtMem->hListBox, LB_SETCURSEL, (WPARAM)ListIndex, 0);
+}
+
+
static VOID
OnSet(PVIRTMEM pVirtMem)
{
BOOL bTranslated;
TCHAR szTitle[64];
TCHAR szMessage[256];
+ INT DriveIndex = 0;
pVirtMem->bSave = TRUE;
0);
if (Index >= 0 && Index < pVirtMem->Count)
{
+ DriveIndex = SendDlgItemMessage(pVirtMem->hSelf,
+ IDC_PAGEFILELIST,
+ LB_GETITEMDATA,
+ 0,
+ 0);
+
/* Check if custom settings are checked */
if (IsDlgButtonChecked(pVirtMem->hSelf,
IDC_CUSTOM) == BST_CHECKED)
/* Check the valid range of the inial size */
if (InitialSize < 2 ||
- InitialSize > pVirtMem->Pagefile[Index].FreeSize)
+ InitialSize > pVirtMem->Pagefile[DriveIndex].FreeSize)
{
if (LoadString(hApplet,
IDS_MESSAGEBOXTITLE,
/* Check the valid range of the maximum size */
if (MaximumSize < InitialSize ||
- MaximumSize > pVirtMem->Pagefile[Index].FreeSize)
+ MaximumSize > pVirtMem->Pagefile[DriveIndex].FreeSize)
{
if (LoadString(hApplet,
IDS_MESSAGEBOXTITLE,
return;
}
- pVirtMem->Pagefile[Index].InitialSize = InitialSize;
- pVirtMem->Pagefile[Index].MaximumSize = MaximumSize;
- pVirtMem->Pagefile[Index].bUsed = TRUE;
+ pVirtMem->Pagefile[DriveIndex].InitialSize = InitialSize;
+ pVirtMem->Pagefile[DriveIndex].MaximumSize = MaximumSize;
+ pVirtMem->Pagefile[DriveIndex].bUsed = TRUE;
+ }
+ else if (IsDlgButtonChecked(pVirtMem->hSelf,
+ IDC_NOPAGEFILE) == BST_CHECKED)
+ {
+ /* Set sizes to -1 */
+ pVirtMem->Pagefile[DriveIndex].InitialSize = -1;
+ pVirtMem->Pagefile[DriveIndex].MaximumSize = -1;
+ pVirtMem->Pagefile[DriveIndex].bUsed = TRUE;
}
else
{
- /* Set sizes to 0 */
- pVirtMem->Pagefile[Index].InitialSize = 0;
- pVirtMem->Pagefile[Index].MaximumSize = 0;
-
- // Check to see if this drive is used for a paging file
- if (IsDlgButtonChecked(pVirtMem->hSelf,
- IDC_NOPAGEFILE) == BST_UNCHECKED)
- {
- pVirtMem->Pagefile[Index].bUsed = TRUE;
- }
- else
- {
- pVirtMem->Pagefile[Index].bUsed = FALSE;
- }
+ pVirtMem->Pagefile[DriveIndex].InitialSize = 0;
+ pVirtMem->Pagefile[DriveIndex].MaximumSize = 0;
+ pVirtMem->Pagefile[DriveIndex].bUsed = TRUE;
}
+
+ UpdatePagefileEntry(pVirtMem, Index, DriveIndex);
}
}
TCHAR szBuffer[64];
MEMORYSTATUSEX MemoryStatus;
ULARGE_INTEGER FreeDiskSpace;
- UINT i, FreeMemMb, PageFileSizeMb;
+ UINT /*i,*/ FreeMemMb /*, PageFileSizeMb*/;
INT Index;
Index = (INT)SendDlgItemMessage(hwndDlg,
SetDlgItemText(hwndDlg, IDC_SPACEAVAIL, szBuffer);
}
- if (pVirtMem->Pagefile[Index].InitialSize != 0 &&
- pVirtMem->Pagefile[Index].MaximumSize != 0)
+ if (pVirtMem->Pagefile[Index].InitialSize == -1 &&
+ pVirtMem->Pagefile[Index].MaximumSize == -1)
+ {
+ /* No pagefile */
+
+ EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), FALSE);
+ EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), FALSE);
+
+ CheckDlgButton(pVirtMem->hSelf, IDC_NOPAGEFILE, BST_CHECKED);
+ }
+ else if (pVirtMem->Pagefile[Index].InitialSize == 0 &&
+ pVirtMem->Pagefile[Index].MaximumSize == 0)
+ {
+ /* System managed size*/
+
+ EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), FALSE);
+ EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), FALSE);
+
+ CheckDlgButton(pVirtMem->hSelf, IDC_SYSMANSIZE, BST_CHECKED);
+ }
+ else
{
+ /* Custom size */
+
/* Enable and fill the custom values */
EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), TRUE);
EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), TRUE);
IDC_CUSTOM,
BST_CHECKED);
}
- else
- {
- /* It's not a custom value */
- EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), FALSE);
- EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), FALSE);
-
- /* Is it system managed */
- if (pVirtMem->Pagefile[Index].bUsed)
- {
- CheckDlgButton(pVirtMem->hSelf,
- IDC_SYSMANSIZE,
- BST_CHECKED);
- }
- else
- {
- CheckDlgButton(pVirtMem->hSelf,
- IDC_NOPAGEFILE,
- BST_CHECKED);
- }
- }
/* Set minimum pagefile size */
SetDlgItemText(hwndDlg, IDC_MINIMUM, _T("2 MB"));
}
/* Set current pagefile size */
+#if 0
PageFileSizeMb = 0;
for (i = 0; i < 26; i++)
{
}
_stprintf(szBuffer, _T("%u MB"), PageFileSizeMb);
SetDlgItemText(hwndDlg, IDC_CURRENT, szBuffer);
+#endif
}
return TRUE;
static VOID
OnInitDialog(HWND hwnd, PVIRTMEM pVirtMem)
{
+ INT i;
+
pVirtMem->hSelf = hwnd;
pVirtMem->hListBox = GetDlgItem(hwnd, IDC_PAGEFILELIST);
pVirtMem->bSave = FALSE;
SetListBoxColumns(pVirtMem->hListBox);
+ for (i = 0; i < 26; i++)
+ {
+ pVirtMem->Pagefile[i].bUsed = FALSE;
+ pVirtMem->Pagefile[i].InitialSize = -1;
+ pVirtMem->Pagefile[i].MaximumSize = -1;
+ }
+
/* Load the pagefile systems from the reg */
- if (ReadPageFileSettings(pVirtMem))
+ ReadPageFileSettings(pVirtMem);
+
+ /* Parse our settings and set up dialog */
+ ParseMemSettings(pVirtMem);
+
+ InitPagefileList(pVirtMem);
+}
+
+
+static VOID
+OnDestroy(PVIRTMEM pVirtMem)
+{
+ INT i;
+
+ for (i = 0; i < 26; i++)
{
- /* Parse our settings and set up dialog */
- ParseMemSettings(pVirtMem);
+ if (pVirtMem->Pagefile[i].pszVolume != NULL)
+ HeapFree(GetProcessHeap(), 0, pVirtMem->Pagefile[i].pszVolume);
}
+
+ if (pVirtMem->szPagingFiles)
+ HeapFree(GetProcessHeap(), 0, pVirtMem->szPagingFiles);
+
+ HeapFree(GetProcessHeap(), 0, pVirtMem);
}
break;
case WM_DESTROY:
- if (pVirtMem->szPagingFiles)
- HeapFree(GetProcessHeap(), 0,
- pVirtMem->szPagingFiles);
- HeapFree(GetProcessHeap(), 0, pVirtMem);
+ OnDestroy(pVirtMem);
break;
case WM_COMMAND: