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

📄 osdlg.cpp

📁 操作系统实验实现进程调度 包括多种算法
💻 CPP
字号:
// OSDlg.cpp : implementation file
//

#include "stdafx.h"
#include "OS.h"
#include "OSDlg.h"
#include "dos.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()

/////////////////////////////////////////////////////////////////////////////
// COSDlg dialog

COSDlg::COSDlg(CWnd* pParent /*=NULL*/)
	: CDialog(COSDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(COSDlg)
	m_time = 0;
	m_star = 0;
	m_star2 = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void COSDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COSDlg)
	DDX_Control(pDX, IDC_jcshow3, m_JCshow3);
	DDX_Control(pDX, IDC_jcshow2, m_JCshow2);
//	DDX_Control(pDX, IDC_runTime, m_RunT);
	DDX_Control(pDX, IDC_jcshow, m_JCshow);
	DDX_Control(pDX, IDC_JClist, m_JClist);
	DDX_Text(pDX, IDC_Tend, m_time);
	DDV_MinMaxInt(pDX, m_time, 0, 1440);
	DDX_Text(pDX, IDC_Tstar, m_star);
	DDV_MinMaxInt(pDX, m_star, 0, 24);
	DDX_Text(pDX, IDC_Tstar2, m_star2);
	DDV_MinMaxInt(pDX, m_star2, 0, 60);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(COSDlg, CDialog)
	//{{AFX_MSG_MAP(COSDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_LBN_SELCHANGE(IDC_JClist, OnJClist)
	ON_BN_CLICKED(IDC_add, Onadd)
	ON_EN_CHANGE(IDC_Tstar, OnTstar)
	ON_EN_CHANGE(IDC_Tend, OnTend)
	ON_BN_CLICKED(IDC_run, Onrun)
	ON_LBN_SELCHANGE(IDC_jcshow, Onjcshow)
	ON_WM_SETCURSOR()
	ON_WM_TIMER()
//	ON_BN_CLICKED(IDC_runTime, OnrunTime)
	ON_BN_CLICKED(IDC_exit, Onexit)
	ON_LBN_SELCHANGE(IDC_jcshow2, Onjcshow2)
	ON_LBN_SELCHANGE(IDC_jcshow3, Onjcshow3)
	ON_EN_CHANGE(IDC_Tstar2, OnTstar2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COSDlg message handlers

BOOL COSDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	count=0;			//初始化数据
	running=0;
	runtime=1;
	Alltime=0;

	// 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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void COSDlg::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 COSDlg::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 COSDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void COSDlg::OnJClist() 
{
	// TODO: Add your control notification handler code here
	
}


void COSDlg::Onadd() 
{
	// TODO: Add your control notification handler code here
	if(m_time!=0 && count<=14 && running==0)
	{
	t_star.Format("%d:%d",m_star%60,m_star2);
	t_end.Format("%d",m_time);
	
	count++;

	n_time[count]=m_time;
	s_time[count].Format("%d",n_time[count]);
	n_fn[count]=0;

	//Alltime+=m_time;
	Alltime=3000;
	n_name[count]=count;
	s_name[count].Format("%d",count);

	n_star[count]=m_star*60+m_star2;
	s_star[count].Format("%d:%d",m_star,m_star2);

	t_JCname.Format("%d",count);
	//if(m_star>=100)
	m_JClist.AddString("   "+t_JCname+"            "+t_star+"           "+t_end);
//	m_JClist.InsertString(1, "asdf");

//SetItemData(1,str);
	AfxMessageBox("进程"+t_JCname+"添加成功!"+"开始运行:"+s_star[count]+"服务时间:"+s_time[count]);
	}
	else
	{
		if(m_time==0)AfxMessageBox("服务时间无!");
		if(count>14)AfxMessageBox("进程不超过15个!");
		if(running==1)AfxMessageBox("正在运行,无法添加!");;
	}
//	n=count;
}

void COSDlg::OnTstar() 
{
	// 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);
	
	UpdateData(FALSE);
	
}

void COSDlg::OnTend() 
{
	// 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);
	
	UpdateData(FALSE);
}

void COSDlg::Onrun() 
{
	
// TODO: Add your control notification handler code here
	DWORD  nowT;
//	CString sss;
	if(running==1)
	{
		AfxMessageBox("已经运行!");
		return ;
	}
	int n=1,j=0;
	nowT=GetTickCount();  
	SetTimer(1000,1000,NULL);
	// TODO: Add your control notification handler code here
	if(count>0)
	{
		running=1;
		
	//AfxMessageBox(s_name[i]);
		for(n=1;n<4;n++)
		{
			for(j=1;j<=count;j++)
				{
				n_fn[j]=0;
		//		str[j]="";
				}
		int i=1;
		GetList(n_star,n_time,n_f,n_s,n_qs,str,n);
		while(i<=count+1)
			{	
		//	sss.Format("%lf",(GetTickCount()-nowT));
			
				if(n==1)
				{
					m_JCshow.AddString(str[i]);
					if(i==count)m_JCshow.AddString(" ");
				}
				if(n==2)
				{
					m_JCshow2.AddString(str[i]);
					if(i==count)m_JCshow2.AddString(" ");
				}
				if(n==3)
				{
					m_JCshow3.AddString(str[i]);
					if(i==count)m_JCshow3.AddString(" ");
				}
				i++;
		//	m_JClist.InsertString(1, "asdf");
			}
		}
	}
	else
	{
		AfxMessageBox("尚未添加进程!");
	}
}


void COSDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	int i;
		if(running==1)
	{
		if(nIDEvent=1000 && runtime<=Alltime)
		{	
		//	s_runTime.Format("%d",runtime);
		//	m_RunT.SetWindowText(s_runTime);
			runtime++;
		}
	}
	CDialog::OnTimer(nIDEvent);
}

void COSDlg::Onjcshow() 
{
	// TODO: Add your control notification handler code here
	
}

void COSDlg::OnOK() 
{
	// TODO: Add extra validation here
	exit(0);
	CDialog::OnOK();
}

BOOL COSDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	// TODO: Add your message handler code here and/or call default
	
	return CDialog::OnSetCursor(pWnd, nHitTest, message);
}


void COSDlg::OnrunTime() 
{
	// TODO: Add your control notification handler code here
	
}

void COSDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

void COSDlg::Onexit() 
{
	// TODO: Add your control notification handler code here
	AfxMessageBox("程序退出!");
//	CDlg cDialog; 
//	cDialog.DoModal(); 
	exit(0);
}

void COSDlg::Onjcshow2() 
{
	// TODO: Add your control notification handler code here
	
}

void COSDlg::Onjcshow3() 
{
	// TODO: Add your control notification handler code here
	
}

void COSDlg::OnTstar2() 
{
	// 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);
	
	UpdateData(FALSE);
}

⌨️ 快捷键说明

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