📄 bankerdlg.cpp
字号:
// BankerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Banker.h"
#include "BankerDlg.h"
#include "ListDialog.h"
#include "RsDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CBankerDlg dialog
CBankerDlg::CBankerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBankerDlg::IDD, pParent)
, nProcess(2)
, nResorce(1)
{
/*m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);*/
m_hIcons[0]=AfxGetApp()->LoadIcon(IDI_ICON1);
m_hIcons[1]=AfxGetApp()->LoadIcon(IDI_ICON2);
m_hIcons[2]=AfxGetApp()->LoadIcon(IDI_ICON3);
m_hIcons[3]=AfxGetApp()->LoadIcon(IDI_ICON4);
m_hIcons[4]=AfxGetApp()->LoadIcon(IDI_ICON5);
m_hIcons[5]=AfxGetApp()->LoadIcon(IDI_ICON6);
m_hIcons[6]=AfxGetApp()->LoadIcon(IDI_ICON7);
m_hIcons[7]=AfxGetApp()->LoadIcon(IDI_ICON8);
}
void CBankerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, nProcess);
DDV_MinMaxUInt(pDX, nProcess, 1, 100);
DDX_Text(pDX, IDC_EDIT2, nResorce);
DDV_MinMaxUInt(pDX, nResorce, 1, 100);
}
BEGIN_MESSAGE_MAP(CBankerDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDOK, &CBankerDlg::OnBnClickedOk)
END_MESSAGE_MAP()
// CBankerDlg message handlers
BOOL CBankerDlg::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_hIcons[1], TRUE); // Set big icon
SetIcon(m_hIcons[0], TRUE); // Set big icon
SetIcon(m_hIcons[2], TRUE); // Set big icon
SetIcon(m_hIcons[3], TRUE); // Set big icon
SetIcon(m_hIcons[4], TRUE); // Set big icon
SetIcon(m_hIcons[5], TRUE); // Set big icon
SetIcon(m_hIcons[6], TRUE); // Set big icon
SetIcon(m_hIcons[7], TRUE); // Set big icon
SetIcon(m_hIcons[3], FALSE); // Set small icon
SetIcon(m_hIcons[1], FALSE); // Set small icon
SetIcon(m_hIcons[2], FALSE); // Set small icon
SetIcon(m_hIcons[3], FALSE); // Set small icon
SetIcon(m_hIcons[4], FALSE); // Set small icon
SetIcon(m_hIcons[5], FALSE); // Set small icon
SetIcon(m_hIcons[6], FALSE); // Set small icon
SetIcon(m_hIcons[7], FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CBankerDlg::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 CBankerDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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_hIcons[6]);
dc.DrawIcon(x, y, m_hIcons[7]);
dc.DrawIcon(x, y, m_hIcons[0]);
dc.DrawIcon(x, y, m_hIcons[1]);
dc.DrawIcon(x, y, m_hIcons[2]);
dc.DrawIcon(x, y, m_hIcons[3]);
dc.DrawIcon(x, y, m_hIcons[4]);
dc.DrawIcon(x, y, m_hIcons[5]);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CBankerDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcons[7]);
}
void CBankerDlg::OnBnClickedOk()
{
UpdateData(true);
ListDialog *ld = new ListDialog(NULL,nProcess,nResorce);
CString str = _T("请输入各资源可利用的最大量!");
RsDialog* rs = new RsDialog(NULL,nProcess,nResorce,str);
do
{
if(rs->DoModal()==IDOK)
{
if(rs->boolean)
for(UINT i=0; i<nResorce; i++)
ld->Work[i] = ld->Available[i] = rs->Data[i];
}
else
return;
}while(!rs->boolean);
AfxMessageBox(_T("请输入各进程当前已分配的资源数量!"));
for(UINT i=0; i<nProcess; i++)
{
str.Format("请输入P%d当前已分配的资源量!",i);
rs->hint = str;
do
{
if(rs->DoModal()==IDOK)
{
if(rs->boolean)
for(UINT j=0; j<nResorce; j++)
ld->Allocation[i][j] = rs->Data[j];
}
else
return;
}while(!rs->boolean);
}
AfxMessageBox(_T("请输入各进程对各类资源的最大需求!"));
for(UINT i=0; i<nProcess; i++)
{
str.Format("请输入P%d对各类资源的最大需求!",i);
rs->hint = str;
do
{
if(rs->DoModal()==IDOK)
{
if(rs->boolean)
for(UINT j=0; j<nResorce; j++)
{
ld->MAX[i][j] = rs->Data[j];
ld->Need[i][j] = ld->MAX[i][j] - ld->Allocation[i][j];
}
}
else
return;
}while(!rs->boolean);
}
if(ld->Safe())
{
ld->safety = _T(" √");
CString path = _T("");
UINT i;
for (i=0; i<nProcess-1; i++)
{
CString cs;
cs.Format("P%d-->",ld->Path[i]);
path += cs;
}
CString cs;
cs.Format("P%d",ld->Path[i]);
path += cs;
ld->SafeSequence = path;
}
else
{
ld->safety = _T(" X");
ld->SafeSequence = _T("");
}
ld->DoModal();
// TODO: Add your control notification handler code here
OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -