MemPage1.cpp
资源名称:OSDemo [点击查看]
上传用户:tianjwyx
上传日期:2007-01-13
资源大小:813k
文件大小:6k
源码类别:
操作系统开发
开发平台:
Visual C++
- // MemPage1.cpp : implementation file
- //
- #include "stdafx.h"
- #include "OSDemo.h"
- #include "MemPage1.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMemPage1 dialog
- CMemPage1::CMemPage1(CWnd* pParent /*=NULL*/)
- : CDialog(CMemPage1::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CMemPage1)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- void CMemPage1::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMemPage1)
- DDX_Control(pDX, IDC_DRAW, m_Draw);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMemPage1, CDialog)
- //{{AFX_MSG_MAP(CMemPage1)
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMemPage1 message handlers
- BOOL CMemPage1::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: Add extra initialization here
- bDraw=false;
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CMemPage1::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- InitGrah();
- if(bDraw)
- //DrawPotLine();
- DrawBar();
- }
- void CMemPage1::InitGrah()
- {
- int i;
- CString crText;
- CClientDC dc(GetDlgItem(IDC_DRAW));
- CPen lPen(PS_SOLID,2,RGB(200,0,50));
- CPen *lOldPen=dc.SelectObject(&lPen);
- CBrush blackBrush;
- blackBrush.CreateSolidBrush(RGB(0,0,0));
- dc.MoveTo(20,0);
- dc.LineTo(20,260);
- dc.LineTo(550,260);
- dc.MoveTo(550,260);
- CPen lDraw(PS_SOLID,1,RGB(200,0,50));
- dc.SelectObject(&lDraw);
- for (i=1;i<=10;i++)
- {
- crText.Format("%d",i*10);
- dc.MoveTo(17,260-25*i);
- dc.LineTo(23,260-25*i);
- DrawText(0,255-25*i,crText);
- }
- for (i=0;i<=3;i++)
- {
- crText.Format("%dK",(int)pow(2,i));
- dc.MoveTo(90+100*i,257);
- dc.LineTo(90+100*i,263);
- DrawText(85+100*i,265,crText);
- }
- DrawText(500,235,"页面大小");
- DrawText(30,0,"命中率");
- dc.SelectObject(lOldPen);
- CBrush ShowBrush;
- CRect rect1(500,80,510,90);
- CRect rect2(500,100,510,110);
- CRect rect3(500,120,510,130);
- ShowBrush.CreateSolidBrush(RGB(200,0,200));
- dc.FillRect(&rect1,&ShowBrush);
- ShowBrush.CreateSolidBrush(RGB(100,0,200));
- dc.FillRect(&rect2,&ShowBrush);
- ShowBrush.CreateSolidBrush(RGB(100,135,100));
- dc.FillRect(&rect3,&ShowBrush);
- dc.FrameRect(&rect1,&blackBrush);
- dc.FrameRect(&rect2,&blackBrush);
- dc.FrameRect(&rect3,&blackBrush);
- DrawText(520,78,"FIFO");
- DrawText(520,98,"OPT");
- DrawText(520,118,"LRU");
- }
- //DEL void CMemPage1::DrawPotLine()
- //DEL {
- //DEL int i;
- //DEL CClientDC dc(GetDlgItem(IDC_DRAW));
- //DEL CPen blackPen(PS_SOLID,1,RGB(0,0,0));
- //DEL for (i=0;i<4;i++)
- //DEL {
- //DEL CPen Pen(PS_SOLID,1,RGB(200,0,200));
- //DEL dc.SelectObject(&Pen);
- //DEL if (i>0)
- //DEL {
- //DEL dc.MoveTo(20+60*(int)pow(2,i-1),260-potFIFO[i-1].rate*25/10);
- //DEL dc.LineTo(20+60*(int)pow(2,i),260-potFIFO[i].rate*25/10);
- //DEL }
- //DEL dc.Ellipse(17+60*pow(2,i),257-potFIFO[i].rate*25/10,23+60*pow(2,i),263-potFIFO[i].rate*25/10);
- //DEL }
- //DEL for (i=0;i<4;i++)
- //DEL {
- //DEL CPen Pen(PS_SOLID,1,RGB(100,0,200));
- //DEL dc.SelectObject(&Pen);
- //DEL if (i>0)
- //DEL {
- //DEL dc.MoveTo(20+60*(int)pow(2,i-1),260-potOPT[i-1].rate*25/10);
- //DEL dc.LineTo(20+60*(int)pow(2,i),260-potOPT[i].rate*25/10);
- //DEL }
- //DEL dc.Ellipse(17+60*pow(2,i),257-potOPT[i].rate*25/10,23+60*pow(2,i),263-potOPT[i].rate*25/10);
- //DEL }
- //DEL for (i=0;i<4;i++)
- //DEL {
- //DEL CPen Pen(PS_SOLID,1,RGB(100,135,100));
- //DEL dc.SelectObject(&Pen);
- //DEL if (i>0)
- //DEL {
- //DEL dc.MoveTo(20+60*(int)pow(2,i-1),260-potLRU[i-1].rate*25/10);
- //DEL dc.LineTo(20+60*(int)pow(2,i),260-potLRU[i].rate*25/10);
- //DEL }
- //DEL dc.Ellipse(17+60*pow(2,i),257-potLRU[i].rate*25/10,23+60*pow(2,i),263-potLRU[i].rate*25/10);
- //DEL }
- //DEL }
- void CMemPage1::DrawText(int x, int y, CString Text)
- {
- CClientDC dc(GetDlgItem(IDC_DRAW));
- CFont m_TextFont;
- m_TextFont.CreateFont(12, 0, 0, 0, FW_NORMAL, 0, FALSE, FALSE,
- DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
- FIXED_PITCH | FF_ROMAN, "宋体");
- TEXTMETRIC tm;
- dc.GetTextMetrics(&tm);
- CFont* oldFont = dc.SelectObject(&m_TextFont);
- dc.SetBkMode(TRANSPARENT);
- COLORREF oldColor = dc.SetTextColor(RGB(0,0,0));
- dc.TextOut(x,y,Text);
- }
- void CMemPage1::DrawBar()
- {
- int i;
- CString RateStr;
- CClientDC dc(GetDlgItem(IDC_DRAW));
- CPen blackPen(PS_SOLID,1,RGB(0,0,0));
- CBrush blackBrush;
- blackBrush.CreateSolidBrush(RGB(0,0,0));
- for (i=0;i<4;i++)
- {
- CPen Pen(PS_SOLID,1,RGB(0,0,0));
- CBrush FIFOBrush;
- FIFOBrush.CreateSolidBrush(RGB(200,0,200));
- dc.SetBkMode(RGB(200,0,200));
- dc.SelectObject(&Pen);
- CRect FIFOBar(60+100*i,257-potFIFO[i].rate*25/10,80+100*i,260);
- RateStr.Format("%d%%",potFIFO[i].rate);
- dc.Rectangle(&FIFOBar);
- dc.FillRect(&FIFOBar,&FIFOBrush);
- dc.FrameRect(&FIFOBar,&blackBrush);
- DrawText(60+100*i,240-potFIFO[i].rate*25/10,RateStr);
- }
- for (i=0;i<4;i++)
- {
- CPen Pen(PS_SOLID,1,RGB(0,0,0));
- CBrush OPTBrush;
- OPTBrush.CreateSolidBrush(RGB(100,0,200));
- dc.SetBkMode(RGB(200,0,200));
- dc.SelectObject(&Pen);
- CRect OPTBar(85+100*i,257-potOPT[i].rate*25/10,105+100*i,260);
- RateStr.Format("%d%%",potOPT[i].rate);
- dc.Rectangle(&OPTBar);
- dc.FillRect(&OPTBar,&OPTBrush);
- dc.FrameRect(&OPTBar,&blackBrush);
- DrawText(85+100*i,240-potOPT[i].rate*25/10,RateStr);
- }
- for (i=0;i<4;i++)
- {
- CPen Pen(PS_SOLID,1,RGB(0,0,0));
- CBrush LRUBrush;
- LRUBrush.CreateSolidBrush(RGB(100,135,100));
- dc.SetBkMode(RGB(200,0,200));
- dc.SelectObject(&Pen);
- CRect LRUBar(110+100*i,257-potLRU[i].rate*25/10,130+100*i,260);
- RateStr.Format("%d%%",potLRU[i].rate);
- dc.Rectangle(&LRUBar);
- dc.FillRect(&LRUBar,&LRUBrush);
- dc.FrameRect(&LRUBar,&blackBrush);
- DrawText(110+100*i,240-potLRU[i].rate*25/10,RateStr);
- }
- }