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

📄 memview.cpp

📁 操作系统实验演示代码(三个实验
💻 CPP
字号:
// MemView.cpp : implementation file
//

#include "stdafx.h"
#include "OSDemo.h"
#include "MemView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMemView dialog


CMemView::CMemView(CWnd* pParent /*=NULL*/)
	: CDialog(CMemView::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMemView)
	//}}AFX_DATA_INIT
}


void CMemView::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMemView)
	DDX_Control(pDX, IDC_MEMVIEW, m_MemView);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMemView, CDialog)
	//{{AFX_MSG_MAP(CMemView)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMemView message handlers

bool CMemView::InitGrah()
{
   CClientDC dc(this); // device context for painting
	CString Text;
	CString Time;
	CString MemRule;
	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(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);
	}
    for (int y=25;y<=220;y+=18)
	{
		dc.MoveTo(58,y);
		dc.LineTo(63,y);
		MemRule.Format("%3dK",(y-25)/18*10);
		DrawText(30,y-5,MemRule);
	}
	
	dc.SelectObject(lOldPen);
	return true;
}

void CMemView::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 CMemView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
    InitGrah();
	if (bPaint==true)
	{	

		for(int i=0;i<MyRect.GetSize();i++)
		{
			DrawRect(MyRect[i].x,MyRect[i].y,MyRect[i].Len,MyRect[i].Height,MyRect[i].crColor,MyRect[i].crText);
		}
	}

	// Do not call CDialog::OnPaint() for painting messages
}

void CMemView::DrawRect(int x, int y, int Len,int Height, COLORREF crColor, CString crText)
{
    CClientDC dc(this);
	if (!bPaint)
	{
		RECT NewRect;
		NewRect.x=x;
		NewRect.y=y;
		NewRect.Height=Height;
		NewRect.crColor=crColor;
		NewRect.crText=crText;
		NewRect.Len=Len;
		MyRect.Add(NewRect);
	}
	CBrush brush;
	CBrush FrameBrush;
	brush.CreateSolidBrush(crColor);
	FrameBrush.CreateSolidBrush(RGB(0,0,200));
	dc.SetBkMode(TRANSPARENT);
	CRect Rect(x,y,x+Len,y+Height);
	//dc.Rectangle(&Rect);
	dc.FrameRect(&Rect,&FrameBrush);
	if (crText.GetLength()>0) 
        DrawText(x+Len/2-strlen(crText)*5/2,y+Height/2-5,crText);
	else
	{
		dc.FillRect(&Rect,&brush);
        dc.FrameRect(&Rect,&FrameBrush);
	}
}

BOOL CMemView::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_wndChart.SubclassDlgItem(IDC_PIECHART1, this);
	// TODO: Add extra initialization here
    bPaint=false;
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CMemView::AddPiece(COLORREF colorBack, int nAngle, const CString &str)
{
      m_wndChart.AddPiece(colorBack,RGB(0,0,0),nAngle,str);
}

⌨️ 快捷键说明

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