⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 virtmem.c

📁 这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * PROJECT:     ReactOS system properties, control panel applet
 * LICENSE:     GPL - See COPYING in the top level directory
 * FILE:        dll/cpl/sysdm/virtual.c
 * PURPOSE:     Virtual memory control dialog
 * COPYRIGHT:   Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
 *
 */

#include "precomp.h"

static BOOL OnSelChange(PVIRTMEM pVirtMem);
static LPCTSTR lpKey = _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management");

static BOOL
ReadPageFileSettings(PVIRTMEM pVirtMem)
{
    HKEY hkey = NULL;
    DWORD dwType;
    DWORD dwDataSize;
    BOOL bRet = FALSE;

    if(RegCreateKeyEx(HKEY_LOCAL_MACHINE,
                      lpKey,
                      0,
                      NULL,
                      REG_OPTION_NON_VOLATILE,
                      KEY_QUERY_VALUE,
                      NULL,
                      &hkey,
                      NULL) == ERROR_SUCCESS)
    {
        if(RegQueryValueEx(hkey,
                           _T("PagingFiles"),
                           NULL,
                           &dwType,
                           NULL,
                           &dwDataSize) == ERROR_SUCCESS)
        {
            pVirtMem->szPagingFiles = (LPTSTR)HeapAlloc(GetProcessHeap(),
                                                        0,
                                                        dwDataSize);
            if (pVirtMem->szPagingFiles != NULL)
            {
                ZeroMemory(pVirtMem->szPagingFiles,
                           dwDataSize);
                if(RegQueryValueEx(hkey,
                                   _T("PagingFiles"),
                                   NULL,
                                   &dwType,
                                   (PBYTE)pVirtMem->szPagingFiles,
                                   &dwDataSize) == ERROR_SUCCESS)
                {
                    bRet = TRUE;
                }
            }
        }
    }

    if (!bRet)
        ShowLastWin32Error(pVirtMem->hSelf);

    if (hkey != NULL)
        RegCloseKey(hkey);

    return bRet;
}


static INT
GetPageFileSizes(LPTSTR lpPageFiles)
{
    while (*lpPageFiles != _T('\0'))
    {
        if (*lpPageFiles == _T(' '))
        {
            lpPageFiles++;
            return (INT)_ttoi(lpPageFiles);
        }

        lpPageFiles++;
    }

    return -1;
}


static VOID
ParseMemSettings(PVIRTMEM pVirtMem)
{
    TCHAR szDrives[1024];    // all drives
    LPTSTR DrivePtr = szDrives;
    TCHAR szDrive[3]; // single drive
    TCHAR szVolume[MAX_PATH];
    TCHAR *szDisplayString;
    INT InitialSize = 0;
    INT MaxSize = 0;
    INT DriveLen;
    INT PgCnt = 0;

    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;

        DrivePtr = _tcsupr(DrivePtr);

        /* copy the 'X:' portion */
        lstrcpyn(szDrive, DrivePtr, sizeof(szDrive) / sizeof(TCHAR));

        if(GetDriveType(DrivePtr) == DRIVE_FIXED)
        {
            /* 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 */
                InitialSize = GetPageFileSizes(pVirtMem->szPagingFiles);
                MaxSize = GetPageFileSizes(pVirtMem->szPagingFiles);

                pVirtMem->Pagefile[PgCnt].InitialValue = InitialSize;
                pVirtMem->Pagefile[PgCnt].MaxValue = MaxSize;
                pVirtMem->Pagefile[PgCnt].bUsed = TRUE;
                lstrcpy(pVirtMem->Pagefile[PgCnt].szDrive, szDrive);
            }
            else
            {
                pVirtMem->Pagefile[PgCnt].InitialValue = 0;
                pVirtMem->Pagefile[PgCnt].MaxValue = 0;
                pVirtMem->Pagefile[PgCnt].bUsed = FALSE;
                lstrcpy(pVirtMem->Pagefile[PgCnt].szDrive, szDrive);
            }

            _tcscpy(szDisplayString, szDrive);
            _tcscat(szDisplayString, _T("\t"));

            /* set a volume label if there is one */
            if (GetVolumeInformation(DrivePtr,
                                     szVolume,
                                     255,
                                     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) || (MaxSize != 0))
            {
                TCHAR szSize[64];

                _stprintf(szSize, _T("%i - %i"), InitialSize, MaxSize);
                _tcscat(szDisplayString, _T("\t"));
                _tcscat(szDisplayString, szSize);
            }

            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);
}


static VOID
WritePageFileSettings(PVIRTMEM pVirtMem)
{
    HKEY hk = NULL;
    TCHAR szPagingFiles[2048];
    INT i;
    INT nPos = 0;
    BOOL bErr = TRUE;

    for(i = 0; i < pVirtMem->Count; ++i)
    {
        if(pVirtMem->Pagefile[i].bUsed)
        {
            TCHAR szText[256];

            _stprintf(szText, _T("%s\\pagefile.sys %i %i"),
                      pVirtMem->Pagefile[i].szDrive,
                      pVirtMem->Pagefile[i].InitialValue,
                      pVirtMem->Pagefile[i].MaxValue);

            /* Add it to our overall registry string */
            lstrcat(szPagingFiles + nPos, szText);

            /* Record the position where the next string will start */
            nPos += (INT)lstrlen(szText) + 1;

            /* add another NULL for REG_MULTI_SZ */
            szPagingFiles[nPos] = _T('\0');
            nPos++;
        }
    }

    if(RegCreateKeyEx(HKEY_LOCAL_MACHINE,
                      lpKey,
                      0,
                      NULL,
                      REG_OPTION_NON_VOLATILE,
                      KEY_WRITE,
                      NULL,
                      &hk,
                      NULL) == ERROR_SUCCESS)
    {
        if (RegSetValueEx(hk,
                          _T("PagingFiles"),
                          0,
                          REG_MULTI_SZ,
                          (LPBYTE) szPagingFiles,
                          (DWORD) nPos * sizeof(TCHAR)) == ERROR_SUCCESS)
        {
            bErr = FALSE;
        }

        RegCloseKey(hk);
    }

    if (bErr)
        ShowLastWin32Error(pVirtMem->hSelf);
}


static VOID
SetListBoxColumns(HWND hwndListBox)
{
    const INT tabs[2] = {30, 170};
    SendMessage(hwndListBox, LB_SETTABSTOPS, (WPARAM)2, (LPARAM)&tabs[0]);
}


static VOID
OnNoPagingFile(PVIRTMEM pVirtMem)
{
    /* Disable the page file custom size boxes */
    EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), FALSE);
    EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), FALSE);
}


static VOID
OnSysManSize(PVIRTMEM pVirtMem)
{
    /* Disable the page file custom size boxes */
    EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), FALSE);
    EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), FALSE);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -