⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jobview.cpp

📁 操作系统实验演示代码(三个实验
💻 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;i<MyRect.GetSize();i++)
		{
			if (MyRect[i].flag)
				DrawRect(MyRect[i].x,MyRect[i].y,MyRect[i].Len,MyRect[i].crColor,MyRect[i].crText);
			else
				DrawDotRect(MyRect[i].x,MyRect[i].y,MyRect[i].Len,MyRect[i].crColor);
		}
	}	
	// Do not call CDialog::OnPaint() for painting messages
}

void CJobView::DrawText(int x, int y, CString Text)
{
    CClientDC dc(this); 
	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 CJobView::DrawRect(int x, int y, int Len, COLORREF crColor, CString crText)
{
    CClientDC dc(this);
	if (!bPaint)
	{
		RECT NewRect;
		NewRect.x=x;
		NewRect.y=y;
		NewRect.crColor=crColor;
		NewRect.crText=crText;
		NewRect.Len=Len;
		NewRect.flag=true;
		MyRect.Add(NewRect);
	}
	
	CBrush brush;
	CBrush FrameBrush;
	brush.CreateSolidBrush(crColor);
	FrameBrush.CreateSolidBrush(RGB(0,0,0));
	dc.SetBkMode(TRANSPARENT);
	CRect Rect(x,y,x+Len,y+15);
	dc.Rectangle(&Rect);
	dc.FrameRect(&Rect,&FrameBrush);
	if (crText.GetLength()>0) 
        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);
}






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -