www.pudn.com > OSDemo.rar > JobView.cpp


// JobView.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "OSDemo.h" 
#include "JobView.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CJobView dialog 
 
 
CJobView::CJobView(CWnd* pParent /*=NULL*/) 
	: CDialog(CJobView::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CJobView) 
	//}}AFX_DATA_INIT 
} 
 
 
void CJobView::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CJobView) 
	DDX_Control(pDX, IDC_JOBVIEW, m_JobView); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CJobView, CDialog) 
	//{{AFX_MSG_MAP(CJobView) 
	ON_WM_PAINT() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CJobView message handlers 
 
 
 
bool CJobView::InitGrah() 
{ 
    CClientDC dc(this); // device context for painting 
	CString Text; 
	CString Time; 
	int CurTime=0; 
	CPen lBlue (PS_SOLID,1,RGB(200,0,50)); 
	CPen *lOldPen=dc.SelectObject(&lBlue); 
    dc.MoveTo(50,15); 
	dc.LineTo(600,15); 
	dc.MoveTo(600,15); 
	dc.LineTo(590,10); 
	dc.MoveTo(600,15); 
	dc.LineTo(590,20); 
	dc.MoveTo(60,20); 
	dc.LineTo(60,220); 
    DrawText(0,0,"时间"); 
	 
	DrawText(5,25,"作业1"); 
	DrawText(5,50,"作业2"); 
	DrawText(5,75,"作业3"); 
	DrawText(5,100,"作业4"); 
	DrawText(5,125,"作业5"); 
	DrawText(5,150,"磁带机A"); 
	DrawText(5,175,"磁带机B"); 
	DrawText(5,200,"打印机"); 
    DrawText(610,10,"说明:"); 
	DrawText(610,25,"为了演示方便,本程序"); 
	DrawText(610,40,"最多只能模拟5个作业,"); 
	DrawText(610,55,"磁带机、打印机资源固定。"); 
    for (int x=60;x<550;x+=50) 
	{ 
		dc.MoveTo(x,13); 
		dc.LineTo(x,18); 
		if (CurTime%60==0) 
		    Time.Format("%d:0%d",8+CurTime/60,CurTime%60); 
	    else 
			Time.Format("%d:%d",8+CurTime/60,CurTime%60); 
		CurTime+=10; 
		DrawText(x-13,2,Time); 
         
	} 
  
	dc.SelectObject(lOldPen); 
 
 
	return true; 
} 
 
void CJobView::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
    InitGrah(); 
    if (bPaint==true) 
	{	 
		CalcRunTime(); 
		for(int i=0;i0)  
        DrawText(x+Len/2-strlen(crText)*5/2,y+2,crText); 
	else 
	{ 
		dc.FillRect(&Rect,&brush); 
        dc.FrameRect(&Rect,&FrameBrush); 
	} 
     
} 
 
//DEL void CJobView::PlayAVI() 
//DEL { 
//DEL     m_aviClock.ShowWindow(SW_SHOW); 
//DEL 	m_aviClock.Play(0,100,2); 
//DEL } 
 
BOOL CJobView::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	//m_aviClock.ShowWindow(SW_HIDE); 
    //m_aviClock.Open(IDR_CLOCK); 
	 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CJobView::DrawDotRect(int x, int y, int len,COLORREF crColor) 
{ 
    CClientDC dc(this); 
	if (!bPaint) 
	{ 
		RECT NewRect; 
		NewRect.x=x; 
		NewRect.y=y; 
		NewRect.crColor=crColor; 
		NewRect.Len=len; 
		NewRect.flag=false; 
		MyRect.Add(NewRect); 
	} 
    CPen lDot (PS_DOT,1,crColor); 
	CPen *lOldPen=dc.SelectObject(&lDot); 
	dc.SetBkMode(TRANSPARENT); 
	dc.MoveTo(x,y); 
	dc.LineTo(x+len,y); 
    dc.LineTo(x+len,y+14); 
	dc.LineTo(x,y+14); 
	dc.LineTo(x,y); 
	dc.SelectObject(&lOldPen); 
} 
 
void CJobView::CalcRunTime() 
{ 
     CString str; 
	 str.Format("加权周转时间:%d 分",SumTime); 
	 DrawText(610,80,str); 
	 str.Format("平均周转时间:%0.2f 分",AveTime); 
	 DrawText(610,100,str); 
}