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

📄 diningguidlg.cpp

📁 哲学家进餐问题
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// DiningGUIDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DiningGUI.h"
#include "DiningGUIDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
CRect rcDinningTable;
CRect CDiningGUIDlg::rcPhil[];
CRect CDiningGUIDlg::rcSpoons[];
SpoonUsage spoonUsage[6];
BITMAP infoSpoon[6];
CString szNames[6];
# include "mPhills.h"
int TooCleverByHalf();
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()

/////////////////////////////////////////////////////////////////////////////
// CDiningGUIDlg dialog

CDiningGUIDlg::CDiningGUIDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDiningGUIDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDiningGUIDlg)
		// 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 CDiningGUIDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDiningGUIDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDiningGUIDlg, CDialog)
	//{{AFX_MSG_MAP(CDiningGUIDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDiningGUIDlg message handlers

BOOL CDiningGUIDlg::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
	
	spoonUsage[0].nSpoonLeftID  = 0;
	spoonUsage[0].nSpoonRightID = 0;
	
	CBitmap map;
	
///////////////////////////////////////////////////////////////////////////
	map.LoadBitmap(IDB_BITMAP_SPOON1);
	map.GetBitmap(&spoonUsage[1].infoSponLeft);
	map.DeleteObject();

	map.LoadBitmap(IDB_BITMAP_SPOON5);
	map.GetBitmap(&spoonUsage[1].infoSponRight);
	map.DeleteObject();

	spoonUsage[1].nSpoonLeftID  = IDC_SPOON1;
	spoonUsage[1].nSpoonRightID = IDC_SPOON5;
	GetDlgItem(spoonUsage[1].nSpoonLeftID)->GetWindowRect(spoonUsage[1].rcLeft); 
	ScreenToClient(spoonUsage[1].rcLeft);
	GetDlgItem(spoonUsage[1].nSpoonRightID)->GetWindowRect(spoonUsage[1].rcRight); 
	ScreenToClient(spoonUsage[1].rcRight);
	szNames[1] = "Plato";
///////////////////////////////////////////////////////////////////////////	
	map.LoadBitmap(IDB_BITMAP_SPOON1);
	map.GetBitmap(&spoonUsage[2].infoSponLeft);
	map.DeleteObject();

	map.LoadBitmap(IDB_BITMAP_SPOON2);
	map.GetBitmap(&spoonUsage[2].infoSponRight);
	map.DeleteObject();

	spoonUsage[2].nSpoonLeftID  = IDC_SPOON1;
	spoonUsage[2].nSpoonRightID = IDC_SPOON2;
	GetDlgItem(spoonUsage[2].nSpoonLeftID)->GetWindowRect(spoonUsage[2].rcLeft); 
	ScreenToClient(spoonUsage[2].rcLeft);
	GetDlgItem(spoonUsage[2].nSpoonRightID)->GetWindowRect(spoonUsage[2].rcRight); 
	ScreenToClient(spoonUsage[2].rcRight);
	szNames[2] = "Konfuzius";
///////////////////////////////////////////////////////////////////////////
	map.LoadBitmap(IDB_BITMAP_SPOON2);
	map.GetBitmap(&spoonUsage[3].infoSponLeft);
	map.DeleteObject();

	map.LoadBitmap(IDB_BITMAP_SPOON3);
	map.GetBitmap(&spoonUsage[3].infoSponRight);
	map.DeleteObject();

	spoonUsage[3].nSpoonLeftID  = IDC_SPOON2;
	spoonUsage[3].nSpoonRightID = IDC_SPOON3;
	GetDlgItem(spoonUsage[3].nSpoonLeftID)->GetWindowRect(spoonUsage[3].rcLeft); 
	ScreenToClient(spoonUsage[3].rcLeft);
	GetDlgItem(spoonUsage[3].nSpoonRightID)->GetWindowRect(spoonUsage[3].rcRight); 
	ScreenToClient(spoonUsage[3].rcRight);
	szNames[3] = "Socrates ";
/////////////////////////////////////////////////////////////////////////////
	map.LoadBitmap(IDB_BITMAP_SPOON3);
	map.GetBitmap(&spoonUsage[4].infoSponLeft);
	map.DeleteObject();

	map.LoadBitmap(IDB_BITMAP_SPOON4);
	map.GetBitmap(&spoonUsage[4].infoSponRight);
	map.DeleteObject();

	spoonUsage[4].nSpoonLeftID  = IDC_SPOON3;
	spoonUsage[4].nSpoonRightID = IDC_SPOON4;
	GetDlgItem(spoonUsage[4].nSpoonLeftID)->GetWindowRect(spoonUsage[4].rcLeft); 
	ScreenToClient(spoonUsage[4].rcLeft);
	GetDlgItem(spoonUsage[4].nSpoonRightID)->GetWindowRect(spoonUsage[4].rcRight); 
	ScreenToClient(spoonUsage[4].rcRight);
	szNames[4] = "Voltaire oval ";
///////////////////////////////////////////////////////////////////////////
	map.LoadBitmap(IDB_BITMAP_SPOON4);
	map.GetBitmap(&spoonUsage[5].infoSponLeft);
	map.DeleteObject();

	map.LoadBitmap(IDB_BITMAP_SPOON5);
	map.GetBitmap(&spoonUsage[5].infoSponRight);
	map.DeleteObject();

	spoonUsage[5].nSpoonLeftID  = IDC_SPOON4;
	spoonUsage[5].nSpoonRightID = IDC_SPOON5;
	GetDlgItem(spoonUsage[5].nSpoonLeftID)->GetWindowRect(spoonUsage[5].rcLeft); 
	ScreenToClient(spoonUsage[5].rcLeft);
	GetDlgItem(spoonUsage[5].nSpoonRightID)->GetWindowRect(spoonUsage[5].rcRight); 
	ScreenToClient(spoonUsage[5].rcRight);
	szNames[5] = "Descartes ";
///////////////////////////////////////////////////////////////////////////
	for(int i=1;i<=5;i++)
	{
		CWnd *wnd = GetDlgItem(IDC_PHILOSOPHOR1+i-1);
		if(wnd)
		{
			wnd->GetWindowRect(rcPhil[i]);
			ScreenToClient(rcPhil[i]);
			wnd->PostMessage(WM_CLOSE);
		}
		wnd = GetDlgItem(IDC_SPOON1+i-1);
		if(wnd)
		{
			wnd->GetWindowRect(rcSpoons[i]);
			ScreenToClient(rcSpoons[i]);
			wnd->PostMessage(WM_CLOSE);
		}
	}
	GetDlgItem(IDC_STATIC_DINNINGTABLE)->GetWindowRect(rcDinningTable);
	ScreenToClient(rcDinningTable);	
	GetDlgItem(IDC_STATIC_DINNINGTABLE)->PostMessage(WM_CLOSE);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CDiningGUIDlg::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 DrawAllSpoons()
{
	CWnd *wnd = AfxGetMainWnd();
	CClientDC dc(wnd);
	CBitmap map;
	CDC	dcMem;
	map.LoadBitmap(IDB_BITMAP_DINNINGTABLE);
	dcMem.CreateCompatibleDC(&dc);
	dcMem.SelectObject(&map);
	BITMAP infoDinning;
	map.GetBitmap(&infoDinning);
	dc.BitBlt(rcDinningTable.left,rcDinningTable.top,
			  infoDinning.bmWidth,infoDinning.bmHeight,
			  &dcMem,0,0,SRCCOPY);
	
	UINT arr[6] ={0, IDB_BITMAP_SPOON1,IDB_BITMAP_SPOON2,IDB_BITMAP_SPOON3,IDB_BITMAP_SPOON4,IDB_BITMAP_SPOON5};
	for(int i=1;i<=5;i++)
	{
		int x = CDiningGUIDlg::rcSpoons[i].left;
		int y = CDiningGUIDlg::rcSpoons[i].top;
		CBitmap map;
		CDC dcMem;

⌨️ 快捷键说明

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