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

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用
#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;
}

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇:jQuery 自动识别浏览器语言

下一篇:从mongoDB中定时导出数据shell脚本