C++图形化动态显示内存占用率的工具

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#include "math.h"
#define Pi 3.1415927

void CMfcSdiSampleView::OnDraw(CDC* pDC)
{
    CMfcSdiSampleDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;

    // TODO: add draw code for native data here
    CRect rect;
    GetClientRect(&rect);
    int radius=800;
    pDC->SetMapMode(MM_ISOTROPIC);
    pDC->SetWindowExt(radius+100,radius+100);
    pDC->SetViewportExt(rect.right/2,-rect.bottom/2);
    pDC->SetViewportOrg(rect.right/2,rect.bottom/2);

    //获取内容状态信息
    MEMORYSTATUS mem;
    ::GlobalMemoryStatus(&mem);
    SIZE_T MemTotal=mem.dwTotalPhys;
    SIZE_T MemAvail=mem.dwAvailPhys;
    double dFree=(double)(Pi*2*MemAvail/MemTotal);
    double dUsed=(double)Pi*2-dFree;
    int x=-(int)(sin(dUsed)*radius);
    int y= (int)(cos(dUsed)*radius);

    CPen pen1,pen2,*oldpen;
    CBrush brush1,brush2,*oldbrush;
    //绘制已用
    pen1.CreatePen(PS_SOLID,50,RGB(255,0,0));
    brush1.CreateSolidBrush(RGB(255,0,0));
    oldpen=pDC->SelectObject(&pen1);
    oldbrush=pDC->SelectObject(&brush1);
    pDC->Pie(-radius,radius,radius,-radius,0,radius,x,y);
    pDC->SelectObject(oldpen);
    pDC->SelectObject(oldbrush);
    //绘制未用
    brush2.CreateSolidBrush(RGB(0,160,255));
    pen2.CreatePen(PS_SOLID,50,RGB(0,160,255));
    oldpen=pDC->SelectObject(&pen2);
    oldbrush=pDC->SelectObject(&brush2);
    pDC->Pie(-radius,radius,radius,-radius,x,y,0,radius);
    pDC->SelectObject(oldpen);
    pDC->SelectObject(oldbrush);

    pDC->SetBkMode(TRANSPARENT);
    CString str;
    str.Format(_T("Total: %dKB"),MemTotal/1024); //物理总内存
    pDC->TextOut(300,300,str);
    str.Format(_T("Available: %dKB"),MemAvail/1024); //剩余内存
    pDC->TextOut(300,200,str);
}

void CMfcSdiSampleView::OnTimer(UINT_PTR nIDEvent)
{
    // TODO: Add your message handler code here and/or call default
    Invalidate();
    CView::OnTimer(nIDEvent);
}

int CMfcSdiSampleView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CView::OnCreate(lpCreateStruct) == -1)
        return -1;

    // TODO:  Add your specialized creation code here
    SetTimer(1,1000,NULL);
    return 0;
}