MemPage2.cpp
资源名称:OSDemo [点击查看]
上传用户:tianjwyx
上传日期:2007-01-13
资源大小:813k
文件大小:4k
源码类别:
操作系统开发
开发平台:
Visual C++
- // MemPage2.cpp : implementation file
- //
- #include "stdafx.h"
- #include "OSDemo.h"
- #include "MemPage2.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMemPage2 dialog
- CMemPage2::CMemPage2(CWnd* pParent /*=NULL*/)
- : CDialog(CMemPage2::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CMemPage2)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- void CMemPage2::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMemPage2)
- DDX_Control(pDX, IDC_DRAW, m_Draw);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMemPage2, CDialog)
- //{{AFX_MSG_MAP(CMemPage2)
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMemPage2 message handlers
- BOOL CMemPage2::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 CMemPage2::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- //InitGrah();
- //if(bDraw)
- // DrawPotLine();
- if(graphComplete)
- {
- CDC* DrawDC=m_Draw.GetDC();
- testGraph->DrawGraph(DrawDC);
- }
- // TODO: Add your message handler code here
- // Do not call CDialog::OnPaint() for painting messages
- }
- void CMemPage2::InitGrah()
- {
- int i;
- CString crText;
- CClientDC dc(GetDlgItem(IDC_DRAW));
- CPen lPen(PS_SOLID,2,RGB(200,0,50));
- CPen *lOldPen=dc.SelectObject(&lPen);
- 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=4;i<=32;i++)
- {
- crText.Format("%d",i);
- dc.MoveTo(20+18*(i-3),257);
- dc.LineTo(20+18*(i-3),263);
- DrawText(20+18*(i-3)-4,265,crText);
- }
- DrawText(480,235,"物理内存页数");
- DrawText(30,0,"命中率");
- dc.SelectObject(lOldPen);
- }
- void CMemPage2::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 CMemPage2::Draw3dLine()
- {
- int i;
- testGraph = new CGraph(LINE_GRAPH_3D);
- testGraph->SetGraphTitle("详细命中情况图");
- testGraph->SetXAxisAlignment(0);
- testGraph->SetXAxisLabel("Memory Page Size (KB)");
- testGraph->SetYAxisLabel("Hit rate");
- testGraph->Set3DDepthRatio(.1);
- testGraph->Set3DLineBase(0,0);
- for (i=0;i<potFIFO.GetSize();i++)
- {
- CGraphSeries* series1 = new CGraphSeries();
- CString AxisStr;
- AxisStr.Format("%d",i+4);
- series1->SetLabel(AxisStr);
- series1->SetData(0, potFIFO[i].rate);
- series1->SetData(1, potOPT[i].rate);
- series1->SetData(2, potLRU[i].rate);
- testGraph->AddSeries(series1);
- if (potFIFO.GetSize()>20) i++;
- }
- testGraph->SetTickLimits(0, 100, 10);
- testGraph->SetColor(0, RED);
- testGraph->SetColor(1, FOREST_GREEN);
- testGraph->SetColor(2, SKY_BLUE);
- //set up legend
- testGraph->SetLegend(0, "FIFO");
- testGraph->SetLegend(1, "OPT");
- testGraph->SetLegend(2, "LRU");
- graphComplete = TRUE;
- Invalidate(TRUE);
- }