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

📄 modelosysdlg.cpp

📁 操作系统内存调度例子
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ModelosysDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Modelosys.h"
#include "ModelosysDlg.h"

#include "InputjobDlg.h"
#include "RandjobDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CModelosysDlg dialog

CModelosysDlg::CModelosysDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CModelosysDlg::IDD, pParent)
{
	number=0;
	Memorysize=64;
	flagshow=NULL; //是否输出Jt表Pt表Mbt表的标志位
	JcbHead=NULL;
	JtHead=NULL;
	PcbHead=NULL;
	PtHead=NULL;
    for(int i=0;i<64;i++)  //初始化内存分配表
	{
		memsize[i].blockid=i+1;
		memsize[i].state=0;
	}
	//{{AFX_DATA_INIT(CModelosysDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CModelosysDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CModelosysDlg)
	DDX_Control(pDX, IDC_LISTPT, m_listpt);
	DDX_Control(pDX, IDC_LISTPCB, m_listpcb);
	DDX_Control(pDX, IDC_LISTMBT, m_listmbt);
	DDX_Control(pDX, IDC_LISTJT, m_listjt);
	DDX_Control(pDX, IDC_LISTJCB, m_listjcb);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CModelosysDlg, CDialog)
	//{{AFX_MSG_MAP(CModelosysDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_INPUTJOB, OnInputjob)
	ON_BN_CLICKED(IDC_RANDJOB, OnRandjob)
	ON_BN_CLICKED(IDC_ABOUT, OnAbout)
	ON_BN_CLICKED(IDC_ALLOCATION, OnAllocation)
	ON_BN_DOUBLECLICKED(IDC_ALLOCATION, OnDoubleclickedAllocation)
	ON_BN_CLICKED(IDC_CLEAR, OnClear)
	ON_BN_DOUBLECLICKED(IDC_CLEAR, OnDoubleclickedClear)
	ON_BN_CLICKED(IDC_EXCUTE, OnExcute)
	ON_BN_DOUBLECLICKED(IDC_EXCUTE, OnDoubleclickedExcute)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CModelosysDlg message handlers

BOOL CModelosysDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_listjcb.InsertColumn(0,"Name",LVCFMT_LEFT,90);
	m_listjcb.InsertColumn(1,"JobId",LVCFMT_LEFT,45);
	m_listjcb.InsertColumn(2,"RTime",LVCFMT_LEFT,45);
	m_listjcb.InsertColumn(3,"MSize",LVCFMT_LEFT,45);
    m_listjcb.InsertColumn(4,"WTime",LVCFMT_LEFT,45);
	m_listjcb.InsertColumn(5,"Rp",LVCFMT_LEFT,50);
	m_listjcb.InsertColumn(6,"State",LVCFMT_LEFT,50);
	
    
	m_listjt.InsertColumn(0,"JobId",LVCFMT_LEFT,105);
	m_listjt.InsertColumn(1,"PtAddr",LVCFMT_LEFT,105);
	m_listjt.InsertColumn(2,"PtLength",LVCFMT_LEFT,101);
	
	m_listpcb.InsertColumn(0,"JobId",LVCFMT_LEFT,85);
    m_listpcb.InsertColumn(1,"Priority",LVCFMT_LEFT,85);
	m_listpcb.InsertColumn(2,"Cputime",LVCFMT_LEFT,85);
	m_listpcb.InsertColumn(3,"State",LVCFMT_LEFT,85);
	
	m_listpt.InsertColumn(0,"Address",LVCFMT_LEFT,70);
    m_listpt.InsertColumn(1,"PageId",LVCFMT_LEFT,50);
	m_listpt.InsertColumn(2,"Block",LVCFMT_LEFT,50);
	
	m_listmbt.InsertColumn(0,"BlockId",LVCFMT_LEFT,55);
	m_listmbt.InsertColumn(1,"State",LVCFMT_LEFT,55);

	OnShowMbt();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CModelosysDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CModelosysDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CModelosysDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CModelosysDlg::OnInputjob() 
{
	// TODO: Add your control notification handler code here
	CInputjobDlg dlg;
	dlg.JcbHead=JcbHead;
	dlg.i=number;
	int Response=dlg.DoModal();
	JcbHead=dlg.JcbHead;
	number=dlg.i;
	if(Response==IDOK)
	{
		number++;
		Jcb *p=new Jcb;
		p->jobname=dlg.m_nJobname;
	    p->runtime=dlg.m_nRuntime;
	    p->memorysize=dlg.m_nMemorysize;
	    p->jobid=number;
	    p->waittime=rand()%11;
	    p->state="wait";
	    p->rp=OnResponse(p->waittime,p->runtime);
	    JcbHead=OnInsert(JcbHead,p);
	}
	OnShowJcb();
}

void CModelosysDlg::OnRandjob() 
{
	// TODO: Add your control notification handler code here
	CRandjobDlg dlg;
	Jcb *p;
	int Response=dlg.DoModal();	
	if(Response==IDOK)
	{
		int j=dlg.m_number;
		for(int i=0;i<j;i++)
		{
			number++;
			p=new Jcb;
			p->jobname="Job";
	        p->runtime=4+rand()%17;
	        p->memorysize=5+rand()%26;
	        p->jobid=number;
	        p->waittime=rand()%11;
	        p->state="wait";
	        p->rp=OnResponse(p->waittime,p->runtime);
	        JcbHead=OnInsert(JcbHead,p);
		}
	}
	OnShowJcb();
}

void CModelosysDlg::OnAbout() 
{
	// TODO: Add your control notification handler code here
	CAboutDlg dlgAbout;
	dlgAbout.DoModal();	
}

void CModelosysDlg::OnAllocation() 
{
	// TODO: Add your control notification handler code here
	if(JcbHead==NULL)
		MessageBox("没有作业,请输入作业之后再调入!",
		          "Modelosys",MB_ICONWARNING);
	else
		if(JcbHead->state=="finish")
		     MessageBox("对不起,没有作业可调入!",
		                "Modelosys",MB_ICONWARNING);
		else
		{
			OnAllocmemory();
	        OnShowa();
		}
}

void CModelosysDlg::OnDoubleclickedAllocation() 
{
	// TODO: Add your control notification handler code here
}

//清除结点并初始化
void CModelosysDlg::OnClear() 
{
	// TODO: Add your control notification handler code here
	if(JcbHead==NULL)
		MessageBox("对不起,没有作业可清除!",
		          "Modelosys",MB_ICONWARNING);
	else
	{
	    flagshow=NULL;
	    Jcb *Jcbp=NULL;
	    Jt* Jtp=NULL;
	    Pcb* Pcbp=NULL;
	    Pt* Ptp=NULL;
	    Memorysize=64;
	    number=0;
        for(int i=0;i<64;i++)  //初始化内存分配表
		{
		    memsize[i].blockid=i+1;
		    memsize[i].state=0;
		}

	    while(JcbHead!=NULL)
		{
		    Jcbp=JcbHead;
		    JcbHead=JcbHead->next;
		    delete Jcbp;
		}
	    while(JtHead!=NULL)
		{
		    Jtp=JtHead;
		    JtHead=JtHead->next;
		    delete Jtp;
		}
	    while(PcbHead!=NULL)
		{
		    Pcbp=PcbHead;
		    PcbHead=PcbHead->next;
		    delete Pcbp;
		}
	    while(PtHead!=NULL)
		{
		    Ptp=PtHead;
		    PtHead=PtHead->next;
		    delete Ptp;
		}
	    OnShowa();
	}
}

void CModelosysDlg::OnDoubleclickedClear() 
{
	// TODO: Add your control notification handler code here
	
}

void CModelosysDlg::OnExcute() 
{
	// TODO: Add your control notification handler code here
	if(JcbHead==NULL)
		MessageBox("对不起,没有作业,请输入作业之后再执行!",
		          "Modelosys",MB_ICONWARNING);
	else
	{
		if(JcbHead->state=="finish"&&PcbHead==NULL)
			MessageBox("作业全部完成,请输入作业之后再执行!",
		               "Modelosys",MB_ICONWARNING);
	    if(JcbHead->state!="finish"&&PcbHead==NULL)
		    MessageBox("对不起,没有创进进程,请调入之后再执行!",
		                "Modelosys",MB_ICONWARNING);
		else
		{
			OnShow();
	        JcbHead=OnChange(JcbHead);
	        OnChange();
		}
	}
}

void CModelosysDlg::OnDoubleclickedExcute() 
{
	// TODO: Add your control notification handler code here
}

void CModelosysDlg::OnShowJcb()
{
	CString str;
	JcbHead=OnExchangeJcb(JcbHead);
	Jcb *p=JcbHead;
	int i=1,j;
	m_listjcb.SetTextColor(RGB(0,0,0));
	m_listjcb.DeleteAllItems();
    while(p!=NULL)
	{
		j=m_listjcb.InsertItem(0,p->jobname);
	    str.Format("%s",p->jobname);
	    m_listjcb.SetItemText(j,0,str);
		if(p->jobname=="Job")
		{
			str.Format("%s%d",p->jobname,i);
			m_listjcb.SetItemText(j,0,str);
		}
	    str.Format("%d",p->jobid);
	    m_listjcb.SetItemText(j,1,str);
	    str.Format("%d",p->runtime);
	    m_listjcb.SetItemText(j,2,str);
		str.Format("%dkb",p->memorysize);
	    m_listjcb.SetItemText(j,3,str);
		str.Format("%d",p->waittime);
	    m_listjcb.SetItemText(j,4,str);
		str.Format("%.2f",p->rp);
	    m_listjcb.SetItemText(j,5,str);
		str.Format("%s",p->state);
	    m_listjcb.SetItemText(j,6,str);
		i++;
		p=p->next;
	}
	JcbHead=OnExchangeJcb(JcbHead);
}

void CModelosysDlg::OnShowPcb()
{
	CString str;
	PcbHead=OnExchangePcb(PcbHead);
	Pcb *p=PcbHead;
	int j;
	m_listpcb.SetTextColor(RGB(10,200,250));
	m_listpcb.DeleteAllItems();
    while(p!=NULL)
	{
		str.Format("%d",p->id);
		j=m_listpcb.InsertItem(0,str);
	    m_listpcb.SetItemText(j,0,str);
	    str.Format("%d",p->priority);
	    m_listpcb.SetItemText(j,1,str);
	    str.Format("%d",p->cputime);
	    m_listpcb.SetItemText(j,2,str);
        str.Format("%s",p->state);
	    m_listpcb.SetItemText(j,3,str);
		p=p->next;
	}
	PcbHead=OnExchangePcb(PcbHead);
}

void CModelosysDlg::OnShowMbt()
{
	CString str;
	int j;
	m_listmbt.SetTextColor(RGB(255,0,0));
	m_listmbt.DeleteAllItems();
    for(int i=63;i>=0;i--)
	{
	    str.Format("%d",memsize[i].blockid);
		j=m_listmbt.InsertItem(0,str);
	    m_listmbt.SetItemText(j,0,str);
	    str.Format("%d",memsize[i].state);
	    m_listmbt.SetItemText(j,1,str);
	}
}

void CModelosysDlg::OnShowJt()
{
	CString str;
    JtHead=OnExchangeJt(JtHead);
	Jt *p=JtHead;
	int j;
	m_listjt.SetTextColor(RGB(0,0,255));
	m_listjt.DeleteAllItems();
    while(p!=NULL)
	{
	    str.Format("%d",p->jobid);
		j=m_listjt.InsertItem(0,str);
	    m_listjt.SetItemText(j,0,str);
	    str.Format("%d",p->ptaddr);
	    m_listjt.SetItemText(j,1,str);
	    str.Format("%d",p->ptlength);
	    m_listjt.SetItemText(j,2,str);
		p=p->next;
	}
	JtHead=OnExchangeJt(JtHead);
}

void CModelosysDlg::OnShowPt()
{
	CString str;
	PtHead=OnExchangePt(PtHead);
	Pt *p=PtHead;
	int j;
	m_listpt.SetTextColor(RGB(180,80,90));
	m_listpt.DeleteAllItems();
    while(p!=NULL)
	{
	    str.Format("%d",p->address);
		j=m_listpt.InsertItem(0,str);
	    m_listpt.SetItemText(j,0,str);
	    str.Format("%d",p->pageid);
	    m_listpt.SetItemText(j,1,str);
	    str.Format("%d",p->block);
	    m_listpt.SetItemText(j,2,str);
		p=p->next;
	}
	PtHead=OnExchangePt(PtHead);
}

void CModelosysDlg::OnShowa()
{

	OnShowPt();
	OnShowMbt();
	OnShowJcb();
    OnShowPcb();
	OnShowJt();
}

void CModelosysDlg::OnShow()
{
	if(flagshow!=NULL)
	{

⌨️ 快捷键说明

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