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

操作系统开发

开发平台:

Visual C++

  1. // JobView.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "OSDemo.h"
  5. #include "JobView.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CJobView dialog
  13. CJobView::CJobView(CWnd* pParent /*=NULL*/)
  14. : CDialog(CJobView::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CJobView)
  17. //}}AFX_DATA_INIT
  18. }
  19. void CJobView::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. //{{AFX_DATA_MAP(CJobView)
  23. DDX_Control(pDX, IDC_JOBVIEW, m_JobView);
  24. //}}AFX_DATA_MAP
  25. }
  26. BEGIN_MESSAGE_MAP(CJobView, CDialog)
  27. //{{AFX_MSG_MAP(CJobView)
  28. ON_WM_PAINT()
  29. //}}AFX_MSG_MAP
  30. END_MESSAGE_MAP()
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CJobView message handlers
  33. bool CJobView::InitGrah()
  34. {
  35.     CClientDC dc(this); // device context for painting
  36. CString Text;
  37. CString Time;
  38. int CurTime=0;
  39. CPen lBlue (PS_SOLID,1,RGB(200,0,50));
  40. CPen *lOldPen=dc.SelectObject(&lBlue);
  41.     dc.MoveTo(50,15);
  42. dc.LineTo(600,15);
  43. dc.MoveTo(600,15);
  44. dc.LineTo(590,10);
  45. dc.MoveTo(600,15);
  46. dc.LineTo(590,20);
  47. dc.MoveTo(60,20);
  48. dc.LineTo(60,220);
  49.     DrawText(0,0,"时间");
  50. DrawText(5,25,"作业1");
  51. DrawText(5,50,"作业2");
  52. DrawText(5,75,"作业3");
  53. DrawText(5,100,"作业4");
  54. DrawText(5,125,"作业5");
  55. DrawText(5,150,"磁带机A");
  56. DrawText(5,175,"磁带机B");
  57. DrawText(5,200,"打印机");
  58.     DrawText(610,10,"说明:");
  59. DrawText(610,25,"为了演示方便,本程序");
  60. DrawText(610,40,"最多只能模拟5个作业,");
  61. DrawText(610,55,"磁带机、打印机资源固定。");
  62.     for (int x=60;x<550;x+=50)
  63. {
  64. dc.MoveTo(x,13);
  65. dc.LineTo(x,18);
  66. if (CurTime%60==0)
  67.     Time.Format("%d:0%d",8+CurTime/60,CurTime%60);
  68.     else
  69. Time.Format("%d:%d",8+CurTime/60,CurTime%60);
  70. CurTime+=10;
  71. DrawText(x-13,2,Time);
  72.         
  73. }
  74.  
  75. dc.SelectObject(lOldPen);
  76. return true;
  77. }
  78. void CJobView::OnPaint() 
  79. {
  80. CPaintDC dc(this); // device context for painting
  81.     InitGrah();
  82.     if (bPaint==true)
  83. {
  84. CalcRunTime();
  85. for(int i=0;i<MyRect.GetSize();i++)
  86. {
  87. if (MyRect[i].flag)
  88. DrawRect(MyRect[i].x,MyRect[i].y,MyRect[i].Len,MyRect[i].crColor,MyRect[i].crText);
  89. else
  90. DrawDotRect(MyRect[i].x,MyRect[i].y,MyRect[i].Len,MyRect[i].crColor);
  91. }
  92. }
  93. // Do not call CDialog::OnPaint() for painting messages
  94. }
  95. void CJobView::DrawText(int x, int y, CString Text)
  96. {
  97.     CClientDC dc(this); 
  98. CFont m_TextFont;
  99. m_TextFont.CreateFont(12, 0, 0, 0, FW_NORMAL, 0, FALSE, FALSE,
  100. DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  101. FIXED_PITCH | FF_ROMAN, "宋体");
  102. TEXTMETRIC tm;
  103. dc.GetTextMetrics(&tm);
  104. CFont* oldFont = dc.SelectObject(&m_TextFont);
  105. dc.SetBkMode(TRANSPARENT);
  106. COLORREF oldColor = dc.SetTextColor(RGB(0,0,0));
  107.     dc.TextOut(x,y,Text);
  108.     
  109. }
  110. void CJobView::DrawRect(int x, int y, int Len, COLORREF crColor, CString crText)
  111. {
  112.     CClientDC dc(this);
  113. if (!bPaint)
  114. {
  115. RECT NewRect;
  116. NewRect.x=x;
  117. NewRect.y=y;
  118. NewRect.crColor=crColor;
  119. NewRect.crText=crText;
  120. NewRect.Len=Len;
  121. NewRect.flag=true;
  122. MyRect.Add(NewRect);
  123. }
  124. CBrush brush;
  125. CBrush FrameBrush;
  126. brush.CreateSolidBrush(crColor);
  127. FrameBrush.CreateSolidBrush(RGB(0,0,0));
  128. dc.SetBkMode(TRANSPARENT);
  129. CRect Rect(x,y,x+Len,y+15);
  130. dc.Rectangle(&Rect);
  131. dc.FrameRect(&Rect,&FrameBrush);
  132. if (crText.GetLength()>0) 
  133.         DrawText(x+Len/2-strlen(crText)*5/2,y+2,crText);
  134. else
  135. {
  136. dc.FillRect(&Rect,&brush);
  137.         dc.FrameRect(&Rect,&FrameBrush);
  138. }
  139.     
  140. }
  141. //DEL void CJobView::PlayAVI()
  142. //DEL {
  143. //DEL     m_aviClock.ShowWindow(SW_SHOW);
  144. //DEL  m_aviClock.Play(0,100,2);
  145. //DEL }
  146. BOOL CJobView::OnInitDialog() 
  147. {
  148. CDialog::OnInitDialog();
  149. //m_aviClock.ShowWindow(SW_HIDE);
  150.     //m_aviClock.Open(IDR_CLOCK);
  151. return TRUE;  // return TRUE unless you set the focus to a control
  152.               // EXCEPTION: OCX Property Pages should return FALSE
  153. }
  154. void CJobView::DrawDotRect(int x, int y, int len,COLORREF crColor)
  155. {
  156.     CClientDC dc(this);
  157. if (!bPaint)
  158. {
  159. RECT NewRect;
  160. NewRect.x=x;
  161. NewRect.y=y;
  162. NewRect.crColor=crColor;
  163. NewRect.Len=len;
  164. NewRect.flag=false;
  165. MyRect.Add(NewRect);
  166. }
  167.     CPen lDot (PS_DOT,1,crColor);
  168. CPen *lOldPen=dc.SelectObject(&lDot);
  169. dc.SetBkMode(TRANSPARENT);
  170. dc.MoveTo(x,y);
  171. dc.LineTo(x+len,y);
  172.     dc.LineTo(x+len,y+14);
  173. dc.LineTo(x,y+14);
  174. dc.LineTo(x,y);
  175. dc.SelectObject(&lOldPen);
  176. }
  177. void CJobView::CalcRunTime()
  178. {
  179.      CString str;
  180.  str.Format("加权周转时间:%d 分",SumTime);
  181.  DrawText(610,80,str);
  182.  str.Format("平均周转时间:%0.2f 分",AveTime);
  183.  DrawText(610,100,str);
  184. }