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

📄 wall_osdlg.cpp

📁 程序功能主要分为3个部分
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// WALL_OSDlg.cpp : implementation file
//

#include "stdafx.h"
#include "WALL_OS.h"
#include "WALL_OSDlg.h"
// 使用页面队列类
#include "PageQueue.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()

/////////////////////////////////////////////////////////////////////////////
// CWALL_OSDlg dialog

CWALL_OSDlg::CWALL_OSDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWALL_OSDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWALL_OSDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	// 初始化页面总数为30,申请到的页面数为10,页面请求序列长度为30
	m_pageAll=30;
	m_pageGot=10;
	m_questLength=30;
}

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

BEGIN_MESSAGE_MAP(CWALL_OSDlg, CDialog)
	//{{AFX_MSG_MAP(CWALL_OSDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_CBN_SELCHANGE(IDC_COMBO_PAGE_ALL, OnSelchangeComboPageAll)
	ON_CBN_SELCHANGE(IDC_COMBO_PAGE_GOT, OnSelchangeComboPageGot)
	ON_CBN_SELCHANGE(IDC_COMBO_PAGE_NUM, OnSelchangeComboPageNum)
	ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
	ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear)
	ON_LBN_SELCHANGE(IDC_LIST_RESULT, OnSelchangeListResult)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWALL_OSDlg message handlers
// 对话框初始化函数
BOOL CWALL_OSDlg::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
	// 设置对话框标题
	SetWindowText("请求调页存储管理系统的设计与实现");

	CString str="";
	int i=0;
	CComboBox * pCBox;

	// 获得页面总数下拉框的操作指针
	pCBox = (CComboBox *)GetDlgItem(IDC_COMBO_PAGE_ALL);
	ASSERT(pCBox != NULL);
	// 初始化页面总数下拉框为1~30(m_pageAll+1)
	for(i=0;i<m_pageAll;i++)
	{
		str.Format("%d",i+1);
		pCBox->AddString(str);
	}
	// 初始化页面总数为30
	pCBox->SetCurSel(i-1);

	// 获得申请的页面数的下拉框操作指针
	pCBox = (CComboBox *)GetDlgItem(IDC_COMBO_PAGE_GOT);
	ASSERT(pCBox != NULL);
	// 初始化申请的页面数为1~10(m_pageGot+1)
	for(i=0;i<m_pageGot;i++)
	{
		str.Format("%d",i+1);
		pCBox->AddString(str);
	}
	// 初始化申请的页面数为10
	pCBox->SetCurSel(i-1);

	// 获得页面请求序列长度下拉框操作指针
	pCBox = (CComboBox *)GetDlgItem(IDC_COMBO_PAGE_NUM);
	ASSERT(pCBox != NULL);
	// 初始化页面请求序列长度为1~30(m_questLength+1)
	for(i=0;i<m_questLength;i++)
	{
		str.Format("%d",i+1);
		pCBox->AddString(str);
	}
	// 初始化页面请求序列长度为30
	pCBox->SetCurSel(i-1);

	// 初始化页面请求序列的30个页号输入框为0~29
	for(i=0;i<30;i++)
	{
		pCBox = (CComboBox *)GetDlgItem(IDC_COMBO1+i);
		ASSERT(pCBox != NULL);
		for(int j=0;j<30;j++)
		{
			str.Format("%d",j);
			pCBox->AddString(str);
		}
		pCBox->SetCurSel(i);
	}
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CWALL_OSDlg::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 CWALL_OSDlg::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 CWALL_OSDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
// 更改进程总页数函数
void CWALL_OSDlg::OnSelchangeComboPageAll() 
{
	// TODO: Add your control notification handler code here
	CComboBox * pCBox;
	pCBox = (CComboBox *)GetDlgItem(IDC_COMBO_PAGE_ALL);
	ASSERT(pCBox != NULL);
	// 更改进程总页数为当前输入值
	m_pageAll = pCBox->GetCurSel() + 1 ;

	int i=0;
	CString str="";
	// 更改页面请求序列输入框的可选项,避免越界的无效输入
	for(i=0;i<30;i++)
	{
		pCBox = (CComboBox *)GetDlgItem(IDC_COMBO1+i);
		ASSERT(pCBox != NULL);
		pCBox-> ResetContent();
		for(int j=0;j<m_pageAll;j++)
		{
			str.Format("%d",j);
			pCBox->AddString(str);
		}
		pCBox->SetCurSel(i%j);
	}
	
	
}
// 更改进程获得页数的函数
void CWALL_OSDlg::OnSelchangeComboPageGot() 
{
	// TODO: Add your control notification handler code here
	CComboBox * pCBox;
	pCBox = (CComboBox *)GetDlgItem(IDC_COMBO_PAGE_GOT);
	ASSERT(pCBox != NULL);
	// 更改进程获得页数值为当前输入值
	m_pageGot = pCBox->GetCurSel() + 1 ;
	
}
// 更改页面请求序列长度的函数
void CWALL_OSDlg::OnSelchangeComboPageNum() 
{
	// TODO: Add your control notification handler code here
	CComboBox * pCBox;
	pCBox = (CComboBox *)GetDlgItem(IDC_COMBO_PAGE_NUM);
	ASSERT(pCBox != NULL);
	// 更改页面请求序列长度为当前输入值
	m_questLength = pCBox->GetCurSel() + 1 ;

	pCBox = (CComboBox *)GetDlgItem(IDC_COMBO_PAGE_NUM);
	ASSERT(pCBox != NULL);
	int i=0;
	// 启用与页面请求序列长度相同的输入框用于用户输入
	for(i=0 ; i<m_questLength ; i++)
	{
		GetDlgItem( IDC_COMBO1 + i)->EnableWindow(TRUE);
	}
	// 禁用多余的输入框,避免无效输入
	for(i=m_questLength ; i < 30 ; i++)
	{
		GetDlgItem( IDC_COMBO1 + i)->EnableWindow(FALSE);
	}		
}
// 开始演示按钮函数
void CWALL_OSDlg::OnButtonStart() 
{
	// TODO: Add your control notification handler code here
	// 首先清除上一次的输出
	OnButtonClear();

	CComboBox * pCBox;
	// 建立页面请求序列数组
	int * questSequence = new int [m_questLength];
	int i=0;
	for(i=0;i<m_questLength;i++)
	{
		pCBox = (CComboBox *)GetDlgItem(IDC_COMBO1+i);
		ASSERT(pCBox != NULL);
		questSequence[i] = pCBox->GetCurSel();
	}

	CListBox * pList = (CListBox *) (GetDlgItem(IDC_LIST_RESULT));
	ASSERT(pList != NULL);

	CString str = "";
	str.Format("进程的总页面数: %d",m_pageAll);
	pList->AddString(str);
	str.Format("进程申请到的页面数:%d",m_pageGot);
	pList->AddString(str);
	str.Format("页面请求个数: %d",m_questLength);
	pList->AddString(str);

	//opt函数
	Optimal(questSequence);
	//fifo函数
	FIFO(questSequence);
	//lru函数
	LRU(questSequence);

	delete [] questSequence;

⌨️ 快捷键说明

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