内存使用监视器[对话框]

#include <windows.h>
#include "resource.h"
#define  IDT_TIMER 3000
BOOL __stdcall DlgProc(HWND, UINT, WPARAM, LPARAM);

int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{
    int nResult = ::DialogBoxParam(
        hInstance,        // 实例句柄
        (LPCTSTR)IDD_MAIN,    // 对话框资源ID号
        NULL,            // 父窗口句柄
        DlgProc,        // 消息处理函数
        NULL);             // 对话框初始化的值,在WM_INITDIALOG消息的lParam参数中取出
    return 0;
}

BOOL __stdcall DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {    
    case WM_INITDIALOG: // 初始化对话框
        ::SetTimer(hDlg, IDT_TIMER, 500, NULL);
        break;
    case WM_TIMER:
        char sz[5][32];
        MEMORYSTATUS ms;
        // 取得内存状态信息
        ::GlobalMemoryStatus(&ms);
        wsprintf(sz[0], "%-5d MB", ms.dwTotalPhys/(1024*1024));
        ::SetWindowText(::GetDlgItem(hDlg, IDC_STATIC1), sz[0]);
        wsprintf(sz[1], "%-5d MB", ms.dwAvailPhys/(1024*1024));
        ::SetWindowText(::GetDlgItem(hDlg, IDC_STATIC2), sz[1]);
        wsprintf(sz[2], "%-5d MB", ms.dwTotalVirtual/(1024*1024));
         ::SetWindowText(::GetDlgItem(hDlg, IDC_STATIC3), sz[2]);
        wsprintf(sz[3], "%-5d MB", ms.dwAvailVirtual/(1024*1024));
        ::SetWindowText(::GetDlgItem(hDlg, IDC_STATIC4), sz[3]);
        wsprintf(sz[4], "%d%%", ms.dwMemoryLoad);
        ::SetWindowText(::GetDlgItem(hDlg, IDC_STATIC5), sz[4]);
        break;
    case WM_COMMAND:
        switch(LOWORD(wParam))
        {
        case IDCANCEL:
            ::EndDialog (hDlg, IDCANCEL);
            break;
        }
        break;
    }
    return 0;
}

 

 

posted @ 2013-04-05 11:01  乾卦  阅读(198)  评论(0编辑  收藏  举报