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

📄 zhhdlg.cpp

📁 pos机前台销售系统
💻 CPP
字号:
// zhhDlg.cpp : implementation file
//

#include "stdafx.h"
#include "zhh.h"
#include "zhhDlg.h"
#include "DlgProxy.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//these code is added myself
//全局变量定义开始
int addstream[10];
int n=255;
int i;
int k;
//全局变量结束
//页表定义结束
//结构体定义
class ppoint
{
private:
	int x;
	int y;
public:
	ppoint(int m=0,int n=-1)
	{
		x=m;
		y=n;
	}
	~ppoint(void)
	{
	}
	 ppoint& operator +(ppoint& pp)
	{
		x+=pp.x;
		y+=pp.y;
		return *this;
	}
	setxandy(int m=0,int n=-1)
	{
		x=m;
		y=n;
	}
	ppoint& operator =(ppoint& pp)
	{
		x=pp.x;
		y=pp.y;
		return *this;
	}
	sety(int n)
	{
		y=n;
	}
	getx(void)
	{
		return x;
	}
	gety(void)
	{
		return y;
	}
};
//页表定义
class tab
{
private:
	ppoint * alist;//首地址
	int size;
public:
	tab(int sz=4);//构造函数定义
	~tab(void);
	ppoint& operator [] (int i);
//	tab& operator = (const ppoint& rhs);
	int listsize(void)const;
};
tab::tab(int sz)
{
	CString string;
	size=sz;
	alist= new ppoint[size];
    for(int i=0;i<size;i++)
		alist[i].setxandy(i);
}
tab::~tab(void)
{
	delete []alist;
}
ppoint& tab::operator [](int n)
{
	return alist[n];
}

int tab::listsize(void)const
{
	return size;
}

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
//自定义函数
CString tranfer(int i)
{
	CString string;
	int n;
	int flag=0;
	for(n=i%10;i!=0;n=i%10)
	{
		switch(n)
		{
		case 0: string+="0"; break;
	    case 1: string+="1"; break;
		case 2: string+="2"; break;
        case 3: string+="3"; break;
        case 4: string+="4"; break;
        case 5: string+="5"; break;
        case 6: string+="6"; break;
        case 7: string+="7"; break;
        case 8: string+="8"; break;
        case 9: string+="9"; break;
		}
	    //flag=1;
		i=i/10;
	}
	string.MakeReverse();
	return string;
}
//自定义函数结束
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()

/////////////////////////////////////////////////////////////////////////////
// CZhhDlg dialog

IMPLEMENT_DYNAMIC(CZhhDlg, CDialog);

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

CZhhDlg::~CZhhDlg()
{
	// If there is an automation proxy for this dialog, set
	//  its back pointer to this dialog to NULL, so it knows
	//  the dialog has been deleted.
	if (m_pAutoProxy != NULL)
		m_pAutoProxy->m_pDialog = NULL;
}

void CZhhDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CZhhDlg)
	DDX_Control(pDX, IDC_COMBO1, m_com1);
	DDX_Control(pDX, IDC_RADIO1, m_radio1);
	DDX_Control(pDX, IDC_LIST1, m_list1);
	DDX_Control(pDX, IDC_EDIT1, m_edit1);
	DDX_Control(pDX, IDC_COMBO3, m_com3);
	DDX_Control(pDX, IDC_COMBO2, m_com2);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CZhhDlg, CDialog)
	//{{AFX_MSG_MAP(CZhhDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CZhhDlg message handlers

BOOL CZhhDlg::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
	CheckRadioButton(IDC_RADIO1,IDC_RADIO2 ,IDC_RADIO1);
	m_com1.AddString("10");
	m_com1.AddString("8");
	m_com1.SelectString(-1,"10");
	m_com2.AddString("2KB");
	m_com2.AddString("4KB");
	m_com2.AddString("8KB");
	m_com2.SelectString(-1,"4KB");
	m_com3.AddString("3");
	m_com3.AddString("4");
	m_com3.AddString("5");
	m_com3.SelectString(-1,"4");
	CString string;
//	int i;
	m_com3.GetWindowText(string);
	if(string=="5")
		i=5;
	else if(string=="4")
		i=4;
	else
		i=3;
	//tab tabbox(i);
	for(int h=0;h <10;h++)
	{
		addstream[h]=-1;
	}

	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

// Automation servers should not exit when a user closes the UI
//  if a controller still holds on to one of its objects.  These
//  message handlers make sure that if the proxy is still in use,
//  then the UI is hidden but the dialog remains around if it
//  is dismissed.

void CZhhDlg::OnClose() 
{
	if (CanExit())
		CDialog::OnClose();
}

void CZhhDlg::OnOK() 
{
	if (CanExit())
		CDialog::OnOK();
}

void CZhhDlg::OnCancel() 
{
	if (CanExit())
		CDialog::OnCancel();
}

BOOL CZhhDlg::CanExit()
{
	// If the proxy object is still around, then the automation
	//  controller is still holding on to this application.  Leave
	//  the dialog around, but hide its UI.
	if (m_pAutoProxy != NULL)
	{
		ShowWindow(SW_HIDE);
		return FALSE;
	}

	return TRUE;
}

void CZhhDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
  //  int k;
	srand(n);
	CString string;
     m_com1.GetWindowText(string);
	 if(string=="10")
		 k=10;
	 else
		 k=8;
	 for(int i=0;i<k;i++)
		 addstream[i]=rand()/50;
	     n=rand();
	 string="";
	 for(int ii=0;ii<k;ii++)
	 {
		 string+=tranfer(addstream[ii]);
		 if(ii!=k-1)
	      string+=":";
	 }
	 m_edit1.SetWindowText(string);
}

void CZhhDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	m_list1.ResetContent();
	CString string;
    tab tabbox(i);
	int select;
	int isfull=0;
	int tabpointer=0;
	////////////////////////
	int fifo_or_lru;
	fifo_or_lru=GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO2);
	if(fifo_or_lru==IDC_RADIO1)
		string="FIFO算法运行情况";
	else
		string="LRU算法运行情况";
	CStatic * pstatic=(CStatic * )GetDlgItem(IDC_STATIC1);
	pstatic->SetWindowText(string);
    //////////////////////////
    if(addstream[0]==-1)
	AfxMessageBox("尚未生成地址流,请先生成地址流!");
    m_com2.GetWindowText(string);
	/////////////////////////
	if(string=="2KB")
      select=20;
	else if(string=="4KB")
		select=40;
	else
		select=80;
	/////////////////////////

	for(int pointer=0;pointer < k;pointer++)
	{
		int shang;
		int yushu;
		int yehao;
		int flag=0;
	//	int tabpointer;
		CString tabstring;
		tabstring="页面中插入指令地址:";
		shang=addstream[pointer]/select;
		yushu=addstream[pointer]%select;
		yehao=shang;
		if(yushu!=0)
			yehao++;
		for(int n=0;n<i;i++)
		{
			if(tabbox[n].gety()==yehao)
			{
				tabstring+=tranfer(yehao);
				tabstring+="    命中";
				if(fifo_or_lru==IDC_RADIO2 && n!=isfull-1)
				{
					ppoint pp=tabbox[n];
					while(n<isfull)
					{
						tabbox[n]=tabbox[n+1];
						n++;
					}
					tabbox[n]=pp;
					flag=1;
					break;
				}
			}
		}
		if(flag==0)
		{
			if(isfull != i)
			{
				tabbox[isfull].sety(yehao);
				isfull++;
			}
			else
			{
				if(fifo_or_lru==IDC_RADIO1)
				{
					tabbox[tabpointer].sety(yehao);
					tabpointer++;
				}
				else
				{
					int k=0;
					while(k<i-1)
					{
						tabbox[k]=tabbox[k+1];
						k++;
					}
					tabbox[k].sety(yehao);
				}
			}
		}
	}
}

⌨️ 快捷键说明

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