毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 课程设计 >> 正文

操作系统课程设计-FIFO页面置换算法

更新时间:2007-10-30:  来源:毕业论文
操作系统课程设计-FIFO页面置换算法|课程设计|计算机数据库课程设计

/******************************************************************

** 文件名: testDlg.cpp

** Copyright (c) 2005  湖南农业大学

** 程序设计: 赵德祥

** 日 期: 2005.5

** 描 述: FIFO页面置换算法演示

** 版 本: 1.0

**------------------------------------------------------

******************************************************************/


#include "stdafx.h"
#include "test.h"
#include "testDlg.h"

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

struct SeqQueue *tier=NULL;
BOOL flag;
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog

CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
 : CDialog(CTestDlg::IDD, pParent)
{
 //{{AFX_DATA_INIT(CTestDlg)
  // 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 CTestDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CTestDlg)
 DDX_Control(pDX, IDC_BACK, m_back);
 //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
 //{{AFX_MSG_MAP(CTestDlg)
 ON_WM_SYSCOMMAND()
 ON_WM_PAINT()
 ON_WM_QUERYDRAGICON()
 ON_COMMAND(ID_EXIT, OnExit)
 ON_COMMAND(ID_ABOUT, OnAbout)
 ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
 ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
 ON_COMMAND(ID_RESTART, OnRestart)
 ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
 ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
 ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
 ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
 ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
 ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
 ON_WM_SHOWWINDOW()
 ON_WM_TIMER()
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers
void Permute(short int x)
{
 flag=true;
 for(int i=0;i<tier->rear;i++){
  if(x==tier->page[i]){
   flag=false;
   return;
  }
 }
 tier->ptr=(tier->ptr+1)%MAXNUM;
 tier->page[tier->front]=x;
 tier->front=(tier->front+1)%MAXNUM;
 tier->rear=tier->rear>MAXNUM?MAXNUM:tier->rear+1;
}

void CTestDlg::InitDemo()
{
 for (int i=0;i<STNUM;i++)
 {
  m_Static[i]->SetBitmap(HBITMAP(hBlt));
 }
 tier->front=0;
 tier->rear=0;
 tier->ptr=-1;
 flag=true;
}

BOOL CTestDlg::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
 MoveWindow(0,0,WIDTH+6,HEIGHT+44);
 CenterWindow();

 bitmap.LoadBitmap(IDB_BACK);
 GetDlgItem(IDC_BACK)->MoveWindow(0,0,640,480,TRUE);
 GetDlgItem(IDC_STATIC1)->MoveWindow(73,189,75,97,TRUE);
    m_Button[0]=(CButton*)GetDlgItem(IDC_BUTTON1);
 m_Button[1]=(CButton*)GetDlgItem(IDC_BUTTON2);
 m_Button[2]=(CButton*)GetDlgItem(IDC_BUTTON3);
 m_Button[3]=(CButton*)GetDlgItem(IDC_BUTTON4);
 m_Button[4]=(CButton*)GetDlgItem(IDC_BUTTON5);
 m_Button[5]=(CButton*)GetDlgItem(IDC_BUTTON6);
 m_Button[6]=(CButton*)GetDlgItem(IDC_BUTTON7);
 m_Button[7]=(CButton*)GetDlgItem(IDC_BUTTON8);
 m_Static[0]=(CStatic*)GetDlgItem(IDC_STATIC1);
 m_Static[1]=(CStatic*)GetDlgItem(IDC_STATIC2);
 m_Static[2]=(CStatic*)GetDlgItem(IDC_STATIC3);
 m_Static[3]=(CStatic*)GetDlgItem(IDC_STATIC4);
 m_Static[4]=(CStatic*)GetDlgItem(IDC_STATIC5);
 m_Static[5]=(CStatic*)GetDlgItem(IDC_STATIC6);
 m_Blt[0].LoadBitmap(IDB_BITMAP1);
 m_Blt[1].LoadBitmap(IDB_BITMAP2);
 m_Blt[2].LoadBitmap(IDB_BITMAP3);
 m_Blt[3].LoadBitmap(IDB_BITMAP4);
 m_Blt[4].LoadBitmap(IDB_BITMAP5);
 m_Blt[5].LoadBitmap(IDB_BITMAP6);
 m_Blt[6].LoadBitmap(IDB_BITMAP7);
 m_Blt[7].LoadBitmap(IDB_BITMAP8);
 hBlt = ::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BITMAP0)); 
 int i;
 for (i=0;i<BTNUM;i++)
 {
  m_Button[i]->MoveWindow(9+78*i,HEIGHT-120,75,97,TRUE);
  m_Button[i]->SetBitmap(HBITMAP(m_Blt[i]));
 }
 for (i=0;i<STNUM-1;i++)
 {
  m_Static[i]->MoveWindow(76+102*i,(HEIGHT-120)/2,75,97,TRUE);
 }
 m_Static[i]->MoveWindow(WIDTH-100,20,75,97,TRUE);
 GetDlgItem(IDC_STATIC)->MoveWindow(WIDTH-113,120,100,20,TRUE);
 tier=(SeqQueue*)malloc(sizeof(struct SeqQueue));
 InitDemo();
 return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTestDlg::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 CTestDlg::DrawBackdrop()
{
 BITMAP bm;
 CDC *pDC=new CDC;
 CClientDC dc(&m_back);
 pDC->CreateCompatibleDC(&dc);
 pDC->SelectObject(bitmap);
 bitmap.GetObject(sizeof(BITMAP),&bm);
 dc.StretchBlt(0,0,640,480,pDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
 delete pDC;
}

void CTestDlg::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();
  DrawBackdrop();
 }
}

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

void CTestDlg::OnExit()
{
 // TODO: Add your command handler code here
 OnCancel();
}

void CTestDlg::OnCancel()
{
 // TODO: Add your message handler code here
 if( ::MessageBox(GetSafeHwnd(), "退出程序吗?","系统提示",
     MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2  ) == IDYES )
 {
  DeleteObject(hBlt);
  CDialog::OnCancel();
 }
 
}

void CTestDlg::OnAbout()
{
 // TODO: Add your command handler code here
 CAboutDlg dlg;
 dlg.DoModal();
}

void CTestDlg::OnRestart()
{
 // TODO: Add your command handler code here
 InitDemo(); 
}

void CTestDlg::SetImage(int n)
{
 Permute(n);
 if(flag){
  m_Static[tier->ptr]->SetBitmap(HBITMAP(m_Blt[n]));
  m_Static[STNUM-1]->SetBitmap(HBITMAP(m_Blt[n]));
 }else{
  m_Static[STNUM-1]->SetBitmap(HBITMAP(hBlt));
 }
}

void CTestDlg::OnButton1()
{
 // TODO: Add your control notification handler code here
 SetImage(0);
}

void CTestDlg::OnButton2()
{
 // TODO: Add your control notification handler code here
 SetImage(1);
}

void CTestDlg::OnButton3()
{
 // TODO: Add your control notification handler code here
 SetImage(2);
}

void CTestDlg::OnButton4()
{
 // TODO: Add your control notification handler code here
 SetImage(3);
}

void CTestDlg::OnButton5()
{
 // TODO: Add your control notification handler code here
 SetImage(4); 
}

void CTestDlg::OnButton6()
{
 // TODO: Add your control notification handler code here
 SetImage(5); 
}

void CTestDlg::OnButton7()
{
 // TODO: Add your control notification handler code here
 SetImage(6); 
}

void CTestDlg::OnButton8()
{
 // TODO: Add your control notification handler code here
 SetImage(7); 
}

void CTestDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
 CDialog::OnShowWindow(bShow, nStatus);
 
 // TODO: Add your message handler code here
}

BOOL CTestDlg::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
 // TODO: Add your specialized code here and/or call the base class
 
 return CDialog::Create(IDD, pParentWnd);
}

void CTestDlg::OnTimer(UINT nIDEvent)
{
 // TODO: Add your message handler code here and/or call default
 CDialog::OnTimer(nIDEvent);
}

// testDlg.h : header file
//

#if !defined(AFX_TESTDLG_H__BC831C21_F558_4681_8EA8_512BDD43AAA8__INCLUDED_)
#define AFX_TESTDLG_H__BC831C21_F558_4681_8EA8_512BDD43AAA8__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define WIDTH 640
#define HEIGHT 480
#define BTNUM 8
#define STNUM 6
#define MAXNUM 5

struct SeqQueue{
 short int page[MAXNUM];
 int ptr;
 int front,rear;
};

/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog

class CTestDlg : public CDialog
{
// Construction
public:
 CTestDlg(CWnd* pParent = NULL); // standard constructor

 CBitmap bitmap;
 CStatic* m_Static[STNUM];
 CButton* m_Button[BTNUM];
 HBITMAP hBlt;
 CBitmap m_Blt[BTNUM];
// Dialog Data
 //{{AFX_DATA(CTestDlg)
 enum { IDD = IDD_TEST_DIALOG };
 CStatic m_back;
 //}}AFX_DATA

 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CTestDlg)
 public:
 virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
 protected:
 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
 //}}AFX_VIRTUAL

// Implementation
protected:
 void DrawBackdrop();
 void InitDemo();
 void SetImage(int n);
 HICON m_hIcon;

 // Generated message map functions
 //{{AFX_MSG(CTestDlg)
 virtual BOOL OnInitDialog();
 afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
 afx_msg void OnPaint();
 afx_msg HCURSOR OnQueryDragIcon();
 afx_msg void OnExit();
 virtual void OnCancel();
 afx_msg void OnAbout();
 afx_msg void OnButton1();
 afx_msg void OnButton2();
 afx_msg void OnRestart();
 afx_msg void OnButton3();
 afx_msg void OnButton4();
 afx_msg void OnButton5();
 afx_msg void OnButton6();
 afx_msg void OnButton7();
 afx_msg void OnButton8();
 afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
 afx_msg void OnTimer(UINT nIDEvent);
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_TESTDLG_H__BC831C21_F558_4681_8EA8_512BDD43AAA8__INCLUDED_)Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=377566

操作系统课程设计-FIFO页面置换算法下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。