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

📄 virtmem.c

📁 这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统
💻 C
📖 第 1 页 / 共 2 页
字号:


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


static VOID
OnSet(PVIRTMEM pVirtMem)
{
    INT Index;
    UINT Value;
    BOOL bTranslated;

    pVirtMem->bSave = TRUE;

    Index  = (INT)SendDlgItemMessage(pVirtMem->hSelf,
                                     IDC_PAGEFILELIST,
                                     LB_GETCURSEL,
                                     0,
                                     0);

    if(Index < pVirtMem->Count)
    {
        /* check if custom settings are checked */
        if(IsDlgButtonChecked(pVirtMem->hSelf,
                              IDC_CUSTOM) == BST_CHECKED)
        {
            Value = GetDlgItemInt(pVirtMem->hSelf,
                                  IDC_INITIALSIZE,
                                  &bTranslated,
                                  FALSE);
            if (!bTranslated)
            {
                /* FIXME: Show error message instead of setting the edit
                          field to the previous value */
                SetDlgItemInt(pVirtMem->hSelf,
                              IDC_INITIALSIZE,
                              pVirtMem->Pagefile[Index].InitialValue,
                              FALSE);
            }
            else
                pVirtMem->Pagefile[Index].InitialValue = Value;

            Value = GetDlgItemInt(pVirtMem->hSelf,
                                  IDC_MAXSIZE,
                                  &bTranslated,
                                  FALSE);
            if (!bTranslated)
            {
                /* FIXME: Show error message instead of setting the edit
                          field to the previous value */
                SetDlgItemInt(pVirtMem->hSelf,
                              IDC_MAXSIZE,
                              pVirtMem->Pagefile[Index].MaxValue,
                              FALSE);
            }
            else
                pVirtMem->Pagefile[Index].MaxValue = Value;
        }
        else
        {
            /* set sizes to 0 */
            pVirtMem->Pagefile[Index].InitialValue = pVirtMem->Pagefile[Index].MaxValue = 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;
            }
        }
    }
}


static BOOL
OnSelChange(PVIRTMEM pVirtMem)
{
    INT Index;

    Index = (INT)SendDlgItemMessage(pVirtMem->hSelf,
                                    IDC_PAGEFILELIST,
                                    LB_GETCURSEL,
                                    0,
                                    0);

    if(Index < pVirtMem->Count)
    {

        if(pVirtMem->Pagefile[Index].InitialValue  != 0 &&
           pVirtMem->Pagefile[Index].MaxValue != 0)
        {
            /* enable and fill the custom values */
            EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_MAXSIZE), TRUE);
            EnableWindow(GetDlgItem(pVirtMem->hSelf, IDC_INITIALSIZE), TRUE);

            SetDlgItemInt(pVirtMem->hSelf,
                          IDC_INITIALSIZE,
                          pVirtMem->Pagefile[Index].InitialValue,
                          FALSE);

            SetDlgItemInt(pVirtMem->hSelf,
                          IDC_MAXSIZE,
                          pVirtMem->Pagefile[Index].MaxValue,
                          FALSE);

            CheckDlgButton(pVirtMem->hSelf,
                           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);
            }
        }
    }

    return TRUE;
}


static VOID
OnOk(PVIRTMEM pVirtMem)
{
    if(pVirtMem->bSave == TRUE)
    {
        WritePageFileSettings(pVirtMem);
    }

    if (pVirtMem->szPagingFiles)
        HeapFree(GetProcessHeap(),
                 0,
                 pVirtMem->szPagingFiles);

    HeapFree(GetProcessHeap(),
             0,
             pVirtMem);
}


static VOID
OnCancel(PVIRTMEM pVirtMem)
{
    if (pVirtMem->szPagingFiles)
        HeapFree(GetProcessHeap(),
                 0,
                 pVirtMem->szPagingFiles);

    HeapFree(GetProcessHeap(),
             0,
             pVirtMem);
}


static PVIRTMEM
OnInitDialog(HWND hwnd)
{
    PVIRTMEM pVirtMem = (PVIRTMEM)HeapAlloc(GetProcessHeap(),
                                            HEAP_ZERO_MEMORY,
                                            sizeof(VIRTMEM));
    if (pVirtMem == NULL)
    {
        EndDialog(hwnd, 0);
    }

    pVirtMem->hSelf = hwnd;
    pVirtMem->hListBox = GetDlgItem(hwnd, IDC_PAGEFILELIST);
    pVirtMem->bSave = FALSE;

    SetListBoxColumns(pVirtMem->hListBox);

    /* Load the pagefile systems from the reg */
    if (ReadPageFileSettings(pVirtMem))
    {
        /* Parse our settings and set up dialog */
        ParseMemSettings(pVirtMem);
    }

    return pVirtMem;
}


INT_PTR CALLBACK
VirtMemDlgProc(HWND hwndDlg,
               UINT uMsg,
               WPARAM wParam,
               LPARAM lParam)
{
    /* there can only be one instance of this dialog */
    static PVIRTMEM pVirtMem = NULL;

    UNREFERENCED_PARAMETER(lParam);

    switch (uMsg)
    {
        case WM_INITDIALOG:
            pVirtMem = OnInitDialog(hwndDlg);
            break;

        case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
                case IDCANCEL:
                    OnCancel(pVirtMem);
                    EndDialog(hwndDlg, 0);
                    return TRUE;

                case IDOK:
                    OnOk(pVirtMem);
                    EndDialog(hwndDlg, 0);
                    return TRUE;

                case IDC_NOPAGEFILE:
                    OnNoPagingFile(pVirtMem);
                    return TRUE;

                case IDC_SYSMANSIZE:
                    OnSysManSize(pVirtMem);
                    return TRUE;

                case IDC_CUSTOM:
                    OnCustom(pVirtMem);
                    return TRUE;

                case IDC_SET:
                    OnSet(pVirtMem);
                    return TRUE;

                case IDC_PAGEFILELIST:
                    switch HIWORD(wParam)
                    {
                        case LBN_SELCHANGE:
                            OnSelChange(pVirtMem);
                            return TRUE;
                    }
                    break;
            }
        }
        break;
    }

    return FALSE;
}

⌨️ 快捷键说明

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