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

📄 showosdlg.cpp

📁 C++实现的模拟操作系统
💻 CPP
字号:
// ShowosDlg.cpp : implementation file
//

#include "stdafx.h"
#include "os.h"
#include "ShowosDlg.h"
#include "help1.h"

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


/////////////////////////////////////////////////////////////////////////////
// CShowosDlg dialog

CImageList Cil1,Cil2;

CShowosDlg::CShowosDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CShowosDlg::IDD, pParent)
{
	ifinput=FALSE;
    ifonshow=0;
	ifinitlist=FALSE;
	//{{AFX_DATA_INIT(CShowosDlg)
	m_showtime = _T("0:0:0");
	m_itimeslice = 5;
	m_strdictate = _T("");
	m_strmidresult = _T("");
	m_showprocess = _T("");
	m_strinput = _T("");
	m_strresult = _T("");
	m_strinfo = _T("");
	m_waita = _T("");
	m_waitb = _T("");
	m_waitc = _T("");
	m_owna = _T("");
	m_ownb = _T("");
	m_ownc = _T("");
	//}}AFX_DATA_INIT
}


void CShowosDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CShowosDlg)
	DDX_Control(pDX, IDC_DISK_TREE, m_showdisk);
	DDX_Control(pDX, IDC_index, m_indexlist);
	DDX_Control(pDX, IDC_WAIT_LIST, m_waitlist);
	DDX_Control(pDX, IDC_READY_LIST, m_readylist);
	DDX_Text(pDX, IDC_show_os_time, m_showtime);
	DDX_Text(pDX, IDC_timeslice, m_itimeslice);
	DDX_Text(pDX, IDC_showdictate, m_strdictate);
	DDX_Text(pDX, IDC_middle_result, m_strmidresult);
	DDX_Text(pDX, IDC_run_process, m_showprocess);
	DDX_Text(pDX, IDC_INPUT, m_strinput);
	DDX_Text(pDX, IDC_RESULT, m_strresult);
	DDX_Text(pDX, IDC_SHOW_INFO, m_strinfo);
	DDX_Text(pDX, IDC_WAITA, m_waita);
	DDX_Text(pDX, IDC_WAITB, m_waitb);
	DDX_Text(pDX, IDC_WAITC, m_waitc);
	DDX_Text(pDX, IDC_OWNA, m_owna);
	DDX_Text(pDX, IDC_OWNB, m_ownb);
	DDX_Text(pDX, IDC_OWNC, m_ownc);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CShowosDlg, CDialog)
	//{{AFX_MSG_MAP(CShowosDlg)
	ON_BN_CLICKED(IDC_carry_out, Oncarryout)
	ON_EN_CHANGE(IDC_INPUT, OnChangeInput)
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShowosDlg message handlers
/////////////////////////////////////////////////////////////////////////////
//更新对话框
/////////////////////////////////////////////////////////////////////////////
void CShowosDlg::Updatashow(){
	if(ifonshow){
		UpdateData(FALSE);
		if(ifinitlist){
			InitList();         //初始化列表控件
			ifinitlist=FALSE;

		}
	
	}
}
/////////////////////////////////////////////////////////////////////////////
//更新等待进程列表
/////////////////////////////////////////////////////////////////////////////
bool CShowosDlg::Updatawaitlist(Smemory memory){
	if(ifonshow){
		CString s;
		int j=0,i=0;
		m_waitlist.DeleteAllItems();
		for(j=0;j<11;j++){
			if(memory.pcb[j].full){
				if(memory.pcb[j].pcb.istate==0){    //判断是否中断
					s.Format("%d",(int)memory.pcb[j].pcb.ID);
					m_waitlist.InsertItem(i,s,0);
					m_waitlist.SetItemText(i,1,memory.pcb[j].pcb.strname);
					s.Format("%d",memory.pcb[j].pcb.waittime);
					m_waitlist.SetItemText(i,2,s);
					i++;
				}
			}
		}
		return TRUE;
	}
	return 0;
}
/////////////////////////////////////////////////////////////////////////////
//更新就绪进程列表
/////////////////////////////////////////////////////////////////////////////
bool CShowosDlg::Updatareadylist(Smemory memory){
		if(ifonshow){
		CString s;
		int j=0,i=0;
		m_readylist.DeleteAllItems();
		for(j=0;j<11;j++){
			if(memory.pcb[j].full){
				if(memory.pcb[j].pcb.istate==1){    //判断是否中断
					s.Format("%d",(int)memory.pcb[j].pcb.ID);
					m_readylist.InsertItem(i,s,0);
					m_readylist.SetItemText(i,1,memory.pcb[j].pcb.strname);
					i++;
				}
			}
		}
		return TRUE;
	}
	return 0;
}
////////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////
bool CShowosDlg::Updataindexlist(Smemory memory){//更新主存列表

	if(ifonshow){
		int i=0,j=0;
		for(i=0;i<64;i++){
			if(memory.index[i]){                       //辨别主存分配表
				memory.usememory[i][0]=memory.usememory[i][1]=1;
				memory.usememory[i][2]=memory.usememory[i][3]=1;
				memory.usememory[i][4]=memory.usememory[i][5]=1;
				memory.usememory[i][6]=memory.usememory[i][7]=1;
			}
			else{
				memory.usememory[i][0]=memory.usememory[i][1]=0;
				memory.usememory[i][2]=memory.usememory[i][3]=0;
				memory.usememory[i][4]=memory.usememory[i][5]=0;
				memory.usememory[i][6]=memory.usememory[i][7]=0;
			}
		}
		CString s;
		m_indexlist.DeleteAllItems();
		s.Format("分配表信息:");
		m_indexlist.InsertItem(0,s,0);
		for(i=63;i>=0;i--){			
			s.Format("%d",memory.index[i]);
			m_indexlist.SetItemText(0,i+1,s);
		
		}

		s.Format("用户区信息:");
		m_indexlist.InsertItem(1,s,0);
		for(j=63;j>=0;j--){
			s.Format("%d",memory.usememory[j][0]);
			m_indexlist.SetItemText(1,j+1,s);
		}
	
	}
		
		return TRUE;
}
	

	
////////////////////////////////////////////////////////////////////////////
void CShowosDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	ifonshow=0;                       //关闭了对话框
	CDialog::OnCancel();
}

void CShowosDlg::OnOK() 
{
	// TODO: Add extra validation here
	ifonshow=0;                       //关闭了对话框
	CDialog::OnOK();
}
//////////////////////////////////////////////////////////////////////
//初始化列表控件
//////////////////////////////////////////////////////////////////////
void CShowosDlg::InitList(){	
	m_waitlist.InsertColumn(0,"进程ID",LVCFMT_LEFT,70,-1);
	m_waitlist.InsertColumn(1,"进程名",LVCFMT_LEFT,70,-1);
	m_waitlist.InsertColumn(2,"等待时间",LVCFMT_LEFT,80,-1);
	m_readylist.InsertColumn(0,"进程ID",LVCFMT_LEFT,70,-1);
	m_readylist.InsertColumn(1,"进程名",LVCFMT_LEFT,70,-1);
	int i=0;CString s;
	for(i=64;i>=0;i--){
		if(i==64){
			m_indexlist.InsertColumn(1,"主存空间分配表",LVCFMT_LEFT,130,-1);
		}
		else{
			s.Format("%d",i);
			m_indexlist.InsertColumn(1,s,LVCFMT_LEFT,35,-1);
		}
	}

}
//////////////////////////////////////////////////////////////////////
HTREEITEM CShowosDlg::InsertTree(HTREEITEM hRoot,char name[6],byte type,int index) //磁盘文件显示
{
	HTREEITEM hreRoot;  //树控制项目句柄
    TV_INSERTSTRUCT TCItem;//插入数据项数据结构
    TCItem.hParent=hRoot;//增加根项
    TCItem.hInsertAfter=TVI_LAST;//在最后项之后
    TCItem.item.mask=TVIF_TEXT|TVIF_PARAM|TVIF_IMAGE|TVIF_SELECTEDIMAGE;//设屏蔽
    TCItem.item.lParam=0;//序号
	
	TCItem.item.pszText=name;
	switch(type)
	{
	case 1:
		TCItem.item.iImage=0;//正常图标
		TCItem.item.iSelectedImage=0;//选中时图标
		break;
	case 2:
		TCItem.item.iImage=1;//正常图标
		TCItem.item.iSelectedImage=1;//选中时图标
		break;
	case 3:
		TCItem.item.iImage=3;//正常图标
		TCItem.item.iSelectedImage=3;//选中时图标
		break;
	}
    hreRoot=m_showdisk.InsertItem(&TCItem);//返回根项句柄
	return hreRoot;
}

///////////////////////////////////////////////////////////////////////
void CShowosDlg::Oncarryout() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	ifinput=TRUE;	
}

void CShowosDlg::OnChangeInput() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	
}

BOOL CShowosDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	COsApp *pApp=(COsApp *)AfxGetApp();//创建图象列表
	if(!Cil1.m_hImageList)
	{
		
		
		Cil1.Create(16,16,ILC_COLOR,4,4);
	}
	Cil1.Add(pApp->LoadIcon(IDI_ICON5));
	Cil1.Add(pApp->LoadIcon(IDI_ICON3));
	Cil1.Add(pApp->LoadIcon(IDI_ICON3));
	Cil1.Add(pApp->LoadIcon(IDI_ICON2));
	m_showdisk.SetImageList(&Cil1,TVSIL_NORMAL); //设置图象列表
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
bool CShowosDlg::Updataabc(Smemory memory,int a,int b[2],int c[2])      //外设显示
{
	if(ifonshow){
		CString s;
		m_waita=m_waitb=m_waitc="";
		for(int i=1;i<11;i++)
		{
			if(memory.pcb[i].full)    //如果有进程
			{
				if(0==memory.pcb[i].pcb.istate)     //如果是中断
				{
					s.Format("%d ",(int)memory.pcb[i].pcb.ID);
					switch(memory.pcb[i].pcb.ihaltreasion)
					{
					case HALT_NA:
						m_waita+=s;
						break;
					case  HALT_NB:
						m_waitb+=s;
						break;
					case HALT_NC:
						m_waitc+=s;
						break;
					case HALT_NBC:
						m_waitb+=s;
						m_waitc+=s;
						break;
					case HALT_NAC:
						m_waita+=s;
						m_waitc+=s;
						break;
					case HALT_NAB:
						m_waita+=s;
						m_waitb+=s;
						break;
					case HALT_NABC:
						m_waita+=s;
						m_waitb+=s;
						m_waitc+=s;
						break;				
					}
				}
			}
		}
		if((int)memory.pcb[a].pcb.ID==99999)
		{
			m_owna.Format("空闲");
		}
		else m_owna.Format("%ld",(int)memory.pcb[a].pcb.ID);

		if((int)memory.pcb[b[0]].pcb.ID==99999&&(int)memory.pcb[b[1]].pcb.ID==99999)
		{
			m_ownb.Format("空闲  空闲");
		}
		else 
			if((int)memory.pcb[b[0]].pcb.ID!=99999&&(int)memory.pcb[b[1]].pcb.ID==99999)
			{
				m_ownb.Format("%ld 空闲",(int)memory.pcb[b[0]].pcb.ID);
			}
			else
				if((int)memory.pcb[b[0]].pcb.ID==99999&&(int)memory.pcb[b[1]].pcb.ID!=99999)
				{
					m_ownb.Format("空闲 %ld",(int)memory.pcb[b[1]].pcb.ID);
				}
				else m_ownb.Format("%ld %ld",(int)memory.pcb[b[0]].pcb.ID,(int)memory.pcb[b[1]].pcb.ID);


		if((int)memory.pcb[c[0]].pcb.ID==99999&&(int)memory.pcb[c[1]].pcb.ID==99999)
		{
			m_ownc.Format("空闲  空闲");
		}
		else 
			if((int)memory.pcb[c[0]].pcb.ID!=99999&&(int)memory.pcb[c[1]].pcb.ID==99999)
			{
				m_ownc.Format("%ld 空闲",(int)memory.pcb[c[0]].pcb.ID);
			}
			else
				if((int)memory.pcb[c[0]].pcb.ID==99999&&(int)memory.pcb[c[1]].pcb.ID!=99999)
				{
					m_ownc.Format("空闲 %ld",(int)memory.pcb[c[1]].pcb.ID);
				}
				else m_ownc.Format("%ld %ld",(int)memory.pcb[c[0]].pcb.ID,(int)memory.pcb[c[1]].pcb.ID);
		
		UpdateData(FALSE);
	}
		return TRUE;
}

void CShowosDlg::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	m_strresult.Format("1 fdisk 格式化分区\r\n2 cd X  进入X盘或者进入目录\r\n3 create adc.e 创建文件abc.e e结尾为执生文件\r\n4 edit abc.e 编缉abc.e文件\r\n5 delete abc.e 删除文件abc.e\r\n6 makdir kdk创建kdk目录 \r\n7 pub 显示当前路径\r\n8 deldir kdk 删除kdk目录所有东西\r\n9 rdir kdk 当kdk目录为空时删除");
}

void CShowosDlg::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	m_strresult.Format("1 CPU类型: 586\r\n2 内存容量:512b\r\n3 硬盘容量:8Kb\r\n4 外设 :A ,B ,C");
}

void CShowosDlg::OnBnClickedButton3()
{
	// TODO: 在此添加控件通知处理程序代码
	m_strresult.Format("CPU内可使用寄存器为ax(默认存放被除数各乘数),bx,cx\r\nmov指令 mov 寄存器,寄存器or数值 如mov ax,bx mov ax,1\r\nadd指令 add 寄存器,寄存器or数值 如add ax,bx add ax,1\r\nsub指令 sub 寄存器,寄存器or数值 如sub cx,bx sub ax,1\r\nmul指令 mul 寄存器 如mul bx \r\ndiv指令 div 寄存器 如div cx \r\n其它指令有:needa,needb needc i++ i--");
}

⌨️ 快捷键说明

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