MemView.cpp
上传用户:tianjwyx
上传日期:2007-01-13
资源大小:813k
文件大小:4k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. // MemView.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "OSDemo.h"
  5. #include "MemView.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CMemView dialog
  13. CMemView::CMemView(CWnd* pParent /*=NULL*/)
  14. : CDialog(CMemView::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CMemView)
  17. //}}AFX_DATA_INIT
  18. }
  19. void CMemView::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. //{{AFX_DATA_MAP(CMemView)
  23. DDX_Control(pDX, IDC_MEMVIEW, m_MemView);
  24. //}}AFX_DATA_MAP
  25. }
  26. BEGIN_MESSAGE_MAP(CMemView, CDialog)
  27. //{{AFX_MSG_MAP(CMemView)
  28. ON_WM_PAINT()
  29. //}}AFX_MSG_MAP
  30. END_MESSAGE_MAP()
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CMemView message handlers
  33. bool CMemView::InitGrah()
  34. {
  35.    CClientDC dc(this); // device context for painting
  36. CString Text;
  37. CString Time;
  38. CString MemRule;
  39. int CurTime=0;
  40. CPen lBlue (PS_SOLID,1,RGB(200,0,50));
  41. CPen *lOldPen=dc.SelectObject(&lBlue);
  42.     dc.MoveTo(50,15);
  43. dc.LineTo(600,15);
  44. dc.MoveTo(600,15);
  45. dc.LineTo(590,10);
  46. dc.MoveTo(600,15);
  47. dc.LineTo(590,20);
  48. dc.MoveTo(60,20);
  49. dc.LineTo(60,220);
  50.     DrawText(0,0,"时间");
  51.     DrawText(610,10,"说明:");
  52. DrawText(610,25,"为了演示方便,本程序");
  53. DrawText(610,40,"最多只能模拟5个作业,");
  54. DrawText(610,55,"磁带机、打印机资源固定。");
  55.     for (int x=60;x<550;x+=50)
  56. {
  57. dc.MoveTo(x,13);
  58. dc.LineTo(x,18);
  59. if (CurTime%60==0)
  60.     Time.Format("%d:0%d",8+CurTime/60,CurTime%60);
  61.     else
  62. Time.Format("%d:%d",8+CurTime/60,CurTime%60);
  63. CurTime+=10;
  64. DrawText(x-13,2,Time);
  65. }
  66.     for (int y=25;y<=220;y+=18)
  67. {
  68. dc.MoveTo(58,y);
  69. dc.LineTo(63,y);
  70. MemRule.Format("%3dK",(y-25)/18*10);
  71. DrawText(30,y-5,MemRule);
  72. }
  73. dc.SelectObject(lOldPen);
  74. return true;
  75. }
  76. void CMemView::DrawText(int x, int y, CString Text)
  77. {
  78.      CClientDC dc(this); 
  79. CFont m_TextFont;
  80. m_TextFont.CreateFont(12, 0, 0, 0, FW_NORMAL, 0, FALSE, FALSE,
  81. DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  82. FIXED_PITCH | FF_ROMAN, "宋体");
  83. TEXTMETRIC tm;
  84. dc.GetTextMetrics(&tm);
  85. CFont* oldFont = dc.SelectObject(&m_TextFont);
  86. dc.SetBkMode(TRANSPARENT);
  87. COLORREF oldColor = dc.SetTextColor(RGB(0,0,0));
  88.     dc.TextOut(x,y,Text);
  89. }
  90. void CMemView::OnPaint() 
  91. {
  92. CPaintDC dc(this); // device context for painting
  93.     InitGrah();
  94. if (bPaint==true)
  95. {
  96. for(int i=0;i<MyRect.GetSize();i++)
  97. {
  98. DrawRect(MyRect[i].x,MyRect[i].y,MyRect[i].Len,MyRect[i].Height,MyRect[i].crColor,MyRect[i].crText);
  99. }
  100. }
  101. // Do not call CDialog::OnPaint() for painting messages
  102. }
  103. void CMemView::DrawRect(int x, int y, int Len,int Height, COLORREF crColor, CString crText)
  104. {
  105.     CClientDC dc(this);
  106. if (!bPaint)
  107. {
  108. RECT NewRect;
  109. NewRect.x=x;
  110. NewRect.y=y;
  111. NewRect.Height=Height;
  112. NewRect.crColor=crColor;
  113. NewRect.crText=crText;
  114. NewRect.Len=Len;
  115. MyRect.Add(NewRect);
  116. }
  117. CBrush brush;
  118. CBrush FrameBrush;
  119. brush.CreateSolidBrush(crColor);
  120. FrameBrush.CreateSolidBrush(RGB(0,0,200));
  121. dc.SetBkMode(TRANSPARENT);
  122. CRect Rect(x,y,x+Len,y+Height);
  123. //dc.Rectangle(&Rect);
  124. dc.FrameRect(&Rect,&FrameBrush);
  125. if (crText.GetLength()>0) 
  126.         DrawText(x+Len/2-strlen(crText)*5/2,y+Height/2-5,crText);
  127. else
  128. {
  129. dc.FillRect(&Rect,&brush);
  130.         dc.FrameRect(&Rect,&FrameBrush);
  131. }
  132. }
  133. BOOL CMemView::OnInitDialog() 
  134. {
  135. CDialog::OnInitDialog();
  136. m_wndChart.SubclassDlgItem(IDC_PIECHART1, this);
  137. // TODO: Add extra initialization here
  138.     bPaint=false;
  139. return TRUE;  // return TRUE unless you set the focus to a control
  140.               // EXCEPTION: OCX Property Pages should return FALSE
  141. }
  142. void CMemView::AddPiece(COLORREF colorBack, int nAngle, const CString &str)
  143. {
  144.       m_wndChart.AddPiece(colorBack,RGB(0,0,0),nAngle,str);
  145. }