MemorySniffer V1.0小程序

 今天仿书上做的一个监控内存的小软件:界面如下:MemorySniffer V1.0小程序_第1张图片

主要代码:

void CYx_MemoryView::OnDraw(CDC* pDC)
{
 CYx_MemoryDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 CString  str;
 double dFree =0 ,  dUse = 0;
 int x = 0,y = 0 ;
 CRect rect;
 CPen Pen;
 CBrush Brush;
 Brush.CreateSolidBrush(RGB(255,0,0)); //画内部
 Pen.CreatePen(PS_SOLID,100,RGB(255,0,0));//画边框
 pDC->SelectObject(&Pen);
 pDC->SelectObject(&Brush);

 ::GlobalMemoryStatus(&myMemory);
 totalMemory = myMemory.dwTotalPhys;
 freeMemory = myMemory.dwAvailPhys;
 GetClientRect( &rect );

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

 dFree = (double) ( PI * 2 * freeMemory/totalMemory);
 dUse = (double)(PI*2 - dFree);

 x = -(int)(sin( dUse ) * RADIUS );
 y = (int)( cos( dUse ) *  RADIUS );

 pDC->Pie(-RADIUS,RADIUS,RADIUS,-RADIUS,0 ,RADIUS,x,y);

 GetMemoryString(&str,totalMemory,"totalmemory");

 pDC->TextOut(300,300,str);
 GetMemoryString(&str,freeMemory,"freememory");
 pDC->TextOut(100,200,str);
    pDC->TextOut(800,800,"Memory Sniffer V1.0");
 pDC->TextOut(750,-800,"author:duanyx");
 pDC->TextOut(750,-900,"Emial:[email protected]");


}
void CYx_MemoryView::GetMemoryString(CString* str,double dMyMemory,PCSTR strTail)
{
 char cTail='K';
 dMyMemory /= 1024;
 if( dMyMemory > 1024 )
 {
  dMyMemory /= 1024;
  cTail = 'M';
 }
 str->Format("%.2f%c%s%s",dMyMemory,cTail,"b ",strTail);
}

你可能感兴趣的:(c)