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

📄 attemperarithmetic.cpp

📁 进程或作业先来先服务、高优先权、按时间片轮转调度算法用API与C语言结合实现,绝对有用.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// AttemperArithmetic.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "AttemperArithmetic.h"
#include "math.h"
#include "MainFrm.h"
#include "AttemperArithmeticDoc.h"
#include "AttemperArithmeticView.h"

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

CAttemperArithmeticView *d;

char st[5][255];
Info GotSet;
FCFS k;
TC tc;
TCSI si;
CString a;
int FinishedTime[5];
int RoundTime[5];
int ValueTime[5];

int slp[5];
int s;
int TCsort[5];
int SerT[5];
int x=150;


UINT Run0(LPVOID pParam);
UINT Run1(LPVOID pParam);

UINT ts0(LPVOID pParam);
UINT ts1(LPVOID pParam);
UINT ts2(LPVOID pParam);
UINT ts3(LPVOID pParam);
UINT ts4(LPVOID pParam);

/////////////////////////////////////////////////////////////////////////////
// CAttemperArithmeticApp

BEGIN_MESSAGE_MAP(CAttemperArithmeticApp, CWinApp)
	//{{AFX_MSG_MAP(CAttemperArithmeticApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_FCFSMUNU, OnFcfsmunu)
	ON_COMMAND(ID_CLEAR, OnClear)
	ON_COMMAND(ID_TimeCycle, OnTimeCycle)
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAttemperArithmeticApp construction

CAttemperArithmeticApp::CAttemperArithmeticApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CAttemperArithmeticApp object

CAttemperArithmeticApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CAttemperArithmeticApp initialization

BOOL CAttemperArithmeticApp::InitInstance()
{
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate

	// such as the name of your company or organization.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CAttemperArithmeticDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CAttemperArithmeticView));
	AddDocTemplate(pDocTemplate);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it.
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();
	


	return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// 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)
		// No message handlers
	//}}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()

// App command to run the dialog
void CAttemperArithmeticApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CAttemperArithmeticApp message handlers

/////////////////////////////////////////////////////////////////////////////
// FCFS dialog


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

void FCFS::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(FCFS)
	DDX_Control(pDX, IDC_COMBO6, m_Thread5Priority);
	DDX_Control(pDX, IDC_COMBO5, m_Thread4Priority);
	DDX_Control(pDX, IDC_COMBO4, m_Thread3Priority);
	DDX_Control(pDX, IDC_COMBO3, m_Thread2Priority);
	DDX_Control(pDX, IDC_COMBO2, m_Thread1Priority);
	//}}AFX_DATA_MAP


}


BEGIN_MESSAGE_MAP(FCFS, CDialog)
	//{{AFX_MSG_MAP(FCFS)
	ON_WM_KILLFOCUS()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// FCFS message handlers

void CAttemperArithmeticApp::OnFcfsmunu() 
{
	// TODO: Add your command handler code here
	d->Cleart();
	FCFS Set;
	Set.DoModal();
}




BOOL FCFS::OnInitDialog() 
{
	CDialog::OnInitDialog();
	// TODO: Add extra initialization here
	this->m_Thread1Priority.SetCurSel(0);
	this->m_Thread2Priority.SetCurSel(0);
	this->m_Thread3Priority.SetCurSel(0);
	this->m_Thread4Priority.SetCurSel(0);
	this->m_Thread5Priority.SetCurSel(0);
	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


/////////////////////////////////////////////////////////////////////////////
// Info dialog


Info::Info(CWnd* pParent /*=NULL*/)
	: CDialog(Info::IDD, pParent)
{
	//{{AFX_DATA_INIT(Info)
	m_n = _T("");
	//}}AFX_DATA_INIT
}


void Info::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Info)
	DDX_Text(pDX, IDC_EDIT1, m_n);
	DDV_MaxChars(pDX, m_n, 255);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Info, CDialog)
	//{{AFX_MSG_MAP(Info)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Info message handlers


BOOL Info::OnInitDialog() 
{
	CDialog::OnInitDialog();
	UpdateData(FALSE);
	// TODO: Add extra initialization here
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void CAttemperArithmeticView::Cleart()
{	
	CClientDC dc(this);
	dc.TextOut(310,200,"                                           ");
}
void CAttemperArithmeticView::ClearScreen()
{	
	CClientDC dc(this);
	dc.TextOut(200,170,"                                                                                           ");
	dc.TextOut(200,200,"                                                                                           ");
}

void CAttemperArithmeticView::EndClear()
{	
	CClientDC dc(this);
	Sleep(8000);
	dc.TextOut(310,200,"                                           ");
	dc.TextOut(310,200,"Execute Finished");

}

void CAttemperArithmeticView::Display0()
{//	AfxMessageBox(st[0]);

	Sleep(slp[0]);
	CClientDC dc(this);
	dc.TextOut(200,170,"You have Set:");
	dc.TextOut(300,170,st[0]);
	dc.TextOut(310,170,st[1]);
	dc.TextOut(320,170,st[2]);
	dc.TextOut(330,170,st[3]);
	dc.TextOut(340,170,st[4]);	
	dc.TextOut(200,200,"Execute Queue:");
	dc.TextOut(310,200,"Thread 1 !");
//	Sleep(8000);
//	dc.TextOut(310,200,"                        ");
	
}
void CAttemperArithmeticView::Display1()
{
//	AfxMessageBox(st[1]);

	Sleep(slp[1]);
	CClientDC dc(this);
	dc.TextOut(200,170,"You have Set:");
	dc.TextOut(300,170,st[0]);
	dc.TextOut(310,170,st[1]);
	dc.TextOut(320,170,st[2]);
	dc.TextOut(330,170,st[3]);
	dc.TextOut(340,170,st[4]);	
	dc.TextOut(200,200,"Execute Queue:");
	dc.TextOut(310,200,"Thread 2 !");
}
void CAttemperArithmeticView::Display2()
{
//	AfxMessageBox(st[1]);

	Sleep(slp[2]);
	CClientDC dc(this);
	dc.TextOut(200,170,"You have Set:");
	dc.TextOut(300,170,st[0]);
	dc.TextOut(310,170,st[1]);
	dc.TextOut(320,170,st[2]);
	dc.TextOut(330,170,st[3]);
	dc.TextOut(340,170,st[4]);	
	dc.TextOut(200,200,"Execute Queue:");
	dc.TextOut(310,200,"Thread 3 !");
}
void CAttemperArithmeticView::Display3()
{
//	AfxMessageBox(st[1]);

	Sleep(slp[3]);
	CClientDC dc(this);
	dc.TextOut(200,170,"You have Set:");
	dc.TextOut(300,170,st[0]);
	dc.TextOut(310,170,st[1]);
	dc.TextOut(320,170,st[2]);
	dc.TextOut(330,170,st[3]);
	dc.TextOut(340,170,st[4]);	
	dc.TextOut(200,200,"Execute Queue:");
	dc.TextOut(310,200,"Thread 4 !");
}
void CAttemperArithmeticView::Display4()
{
//	AfxMessageBox(st[1]);

	Sleep(slp[4]);
	CClientDC dc(this);
	dc.TextOut(200,170,"You have Set:");
	dc.TextOut(300,170,st[0]);
	dc.TextOut(310,170,st[1]);
	dc.TextOut(320,170,st[2]);
	dc.TextOut(330,170,st[3]);
	dc.TextOut(340,170,st[4]);	
	dc.TextOut(200,200,"Execute Queue:");
	dc.TextOut(310,200,"Thread 5 !");
}


UINT Run0(LPVOID pParam)
{
	d->Display0();
	return 0;
}
UINT Run1(LPVOID pParam)
{
	d->Display1();
	return 0;
}
UINT Run2(LPVOID pParam)
{
	d->Display2();
	return 0;
}
UINT Run3(LPVOID pParam)
{
	d->Display3();
	return 0;
}
UINT Run4(LPVOID pParam)
{
	d->Display4();
	return 0;
}
UINT RunEnd(LPVOID pParam)
{
	d->EndClear();
	return 0;
}

void FCFS::OnKillFocus(CWnd* pNewWnd) 
{
	CDialog::OnKillFocus(pNewWnd);
	UpdateData(TRUE);
	Info m;
	this->m_Thread1Priority.GetLBText(m_Thread1Priority.GetCurSel(),st[0]);
	this->m_Thread2Priority.GetLBText(m_Thread2Priority.GetCurSel(),st[1]);
	this->m_Thread2Priority.GetLBText(m_Thread3Priority.GetCurSel(),st[2]);
	this->m_Thread2Priority.GetLBText(m_Thread4Priority.GetCurSel(),st[3]);
	this->m_Thread2Priority.GetLBText(m_Thread5Priority.GetCurSel(),st[4]);
	m0=(CString)st[0];
	m1=(CString)st[1];
	m2=(CString)st[2];
	m3=(CString)st[3];
	m4=(CString)st[4];

	if (m0=="0")
		slp[0]=500;
	if (m0=="1")
		slp[0]=2000;
	if (m0=="2")
		slp[0]=3500;
	if (m0=="3")
		slp[0]=5000;
	if (m0=="4")
		slp[0]=6500;

	if (m1=="0")
		slp[1]=500;
	if (m1=="1")
		slp[1]=2000;
	if (m1=="2")
		slp[1]=3500;
	if (m1=="3")
		slp[1]=5000;
	if (m1=="4")
		slp[1]=6500;

	if (m2=="0")
		slp[2]=500;
	if (m2=="1")
		slp[2]=2000;
	if (m2=="2")
		slp[2]=3500;
	if (m2=="3")
		slp[2]=5000;
	if (m2=="4")
		slp[2]=6500;

	if (m3=="0")
		slp[3]=500;
	if (m3=="1")
		slp[3]=2000;
	if (m3=="2")
		slp[3]=3500;
	if (m3=="3")
		slp[3]=5000;
	if (m3=="4")
		slp[3]=6500;


	if (m4=="0")
		slp[4]=500;
	if (m4=="1")
		slp[4]=2000;
	if (m4=="2")
		slp[4]=3500;
	if (m4=="3")
		slp[4]=5000;
	if (m4=="4")
		slp[4]=6500;



	Info GotSet;
	for (int i=0;i<5;i++)
	GotSet.m_n=GotSet.m_n+"  "+st[i];
	GotSet.DoModal();

	// TODO: Add your message handler code here*/
	HWND hWnd=GetSafeHwnd();
	p0Thread = AfxBeginThread(Run0,hWnd);
	p1Thread = AfxBeginThread(Run1,hWnd);
	p2Thread = AfxBeginThread(Run2,hWnd);
	p3Thread = AfxBeginThread(Run3,hWnd);
	p4Thread = AfxBeginThread(Run4,hWnd);
	pEndThread = AfxBeginThread(RunEnd,hWnd);
}


void CAttemperArithmeticApp::OnClear() 
{
	// TODO: Add your command handler code here
	d->ClearScreen();
}


/////////////////////////////////////////////////////////////////////////////
// TC dialog


TC::TC(CWnd* pParent /*=NULL*/)
	: CDialog(TC::IDD, pParent)
{
	//{{AFX_DATA_INIT(TC)
	m_TS = 1;
	m_Ser1 = 1;
	m_Ser2 = 1;
	m_Ser3 = 1;
	m_Ser4 = 1;
	m_Ser5 = 1;
	//}}AFX_DATA_INIT
}


void TC::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(TC)
	DDX_Control(pDX, IDC_COMBO10, m_Arr5);
	DDX_Control(pDX, IDC_COMBO9, m_Arr4);
	DDX_Control(pDX, IDC_COMBO8, m_Arr3);
	DDX_Control(pDX, IDC_COMBO7, m_Arr2);
	DDX_Control(pDX, IDC_COMBO1, m_Arr1);
	DDX_Text(pDX, IDC_EDIT1, m_TS);
	DDV_MinMaxInt(pDX, m_TS, 1, 5);
	DDX_Text(pDX, IDC_EDIT2, m_Ser1);
	DDV_MinMaxInt(pDX, m_Ser1, 1, 2147483647);
	DDX_Text(pDX, IDC_EDIT3, m_Ser2);
	DDV_MinMaxInt(pDX, m_Ser2, 1, 2147483647);
	DDX_Text(pDX, IDC_EDIT4, m_Ser3);
	DDV_MinMaxInt(pDX, m_Ser3, 1, 1111111);
	DDX_Text(pDX, IDC_EDIT5, m_Ser4);
	DDV_MinMaxInt(pDX, m_Ser4, 1, 2147483647);
	DDX_Text(pDX, IDC_EDIT6, m_Ser5);
	DDV_MinMaxInt(pDX, m_Ser5, 1, 2147483647);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(TC, CDialog)
	//{{AFX_MSG_MAP(TC)
	ON_WM_KILLFOCUS()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// TC message handlers
void CAttemperArithmeticApp::OnTimeCycle() 
{
	// TODO: Add your command handler code here]
	TC tc;
	tc.DoModal();
}

BOOL TC::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	this->m_Arr1.SetCurSel(0);
	this->m_Arr2.SetCurSel(0);
	this->m_Arr3.SetCurSel(0);
	this->m_Arr4.SetCurSel(0);
	this->m_Arr5.SetCurSel(0);
	UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
UINT tcInit(LPVOID pParam)
{
	d->DspyInit();
	return 0;
}
/////////////////Thread0-4
UINT ts0(LPVOID pParam)

⌨️ 快捷键说明

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