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

📄 philosopherview.h

📁 关于操作系统哲学家进餐的动态演示程序
💻 H
字号:
// PhilosopherView.h : interface of the CPhilosopherView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_PHILOSOPHERVIEW_H__47A6615C_3896_4F40_B28F_94B9BF9EDA4D__INCLUDED_)
#define AFX_PHILOSOPHERVIEW_H__47A6615C_3896_4F40_B28F_94B9BF9EDA4D__INCLUDED_

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

#include <afxmt.h>

#define DEGRESS_TO_RADIAN(x) (x) * 3.14 / 180
#define CHOP_COORDINATE(x, y)																  \
	chopStartX[0] = (x) + 3 * DESK_DIAMETER / 4;					                          \
	chopStartY[0] = (y) + DESK_DIAMETER / 2;												  \
	chopEndX[0] = (x) + DESK_DIAMETER;									                      \
    chopEndY[0] = (y) + DESK_DIAMETER / 2;								                      \
	chopStartX[1] = (int)((x) + DESK_DIAMETER / 2 + DESK_DIAMETER / 4 * sin(DEGRESS_TO_RADIAN(30))); \
	chopStartY[1] = (int)((y) + DESK_DIAMETER / 2 - DESK_DIAMETER / 4 * cos(DEGRESS_TO_RADIAN(30))); \
	chopEndX[1] = (int)((x) + DESK_DIAMETER / 2 + DESK_DIAMETER / 2 * sin(DEGRESS_TO_RADIAN(30)));   \
    chopEndY[1] = (int)((y) + DESK_DIAMETER / 2 - DESK_DIAMETER / 2 * cos(DEGRESS_TO_RADIAN(30)));   \
    chopStartX[2] = (int)((x) + DESK_DIAMETER / 2 - DESK_DIAMETER / 4 * sin(DEGRESS_TO_RADIAN(30))); \
    chopStartY[2] = (int)((y) + DESK_DIAMETER / 2 - DESK_DIAMETER / 4 * cos(DEGRESS_TO_RADIAN(30))); \
    chopEndX[2] = (int)((x) + DESK_DIAMETER / 2 - DESK_DIAMETER / 2 * sin(DEGRESS_TO_RADIAN(30)));   \
    chopEndY[2] = (int)((y) + DESK_DIAMETER / 2 - DESK_DIAMETER / 2 * cos(DEGRESS_TO_RADIAN(30)));   \
	chopStartX[3] = (x) + DESK_DIAMETER / 4;							                      \
	chopStartY[3] = (y) + DESK_DIAMETER / 2;							                      \
    chopEndX[3] = (x);													                      \
	chopEndY[3] = (y) + DESK_DIAMETER / 2; 								                      \
	chopStartX[4] = (int)((x) + DESK_DIAMETER / 2 - DESK_DIAMETER / 4 * sin(DEGRESS_TO_RADIAN(30))); \
    chopStartY[4] = (int)((y) + DESK_DIAMETER / 2 + DESK_DIAMETER / 4 * cos(DEGRESS_TO_RADIAN(30))); \
    chopEndX[4] = (int)((x) + DESK_DIAMETER / 2 - DESK_DIAMETER / 2 * sin(DEGRESS_TO_RADIAN(30)));   \
    chopEndY[4] = (int)((y) + DESK_DIAMETER / 2 + DESK_DIAMETER / 2 * cos(DEGRESS_TO_RADIAN(30)));   \
	chopStartX[5] = (int)((x) + DESK_DIAMETER / 2 + DESK_DIAMETER / 4 * sin(DEGRESS_TO_RADIAN(30))); \
    chopStartY[5] = (int)((y) + DESK_DIAMETER / 2 + DESK_DIAMETER / 4 * cos(DEGRESS_TO_RADIAN(30))); \
    chopEndX[5] = (int)((x) + DESK_DIAMETER / 2 + DESK_DIAMETER / 2 * sin(DEGRESS_TO_RADIAN(30)));   \
    chopEndY[5] = (int)((y) + DESK_DIAMETER / 2 + DESK_DIAMETER / 2 * cos(DEGRESS_TO_RADIAN(30)));

#define PHIL_COORDINATE(x, y)											       \
	philX[0] = (int)((x) + DESK_DIAMETER /2 +										   \
			(DESK_DIAMETER / 2 + PHIL_DIAMETER) * cos(DEGRESS_TO_RADIAN(30)) - \
			PHIL_DIAMETER / 2);												   \
    philY[0] = (int)((y) + DESK_DIAMETER /2 -									       \
			(DESK_DIAMETER / 2 + PHIL_DIAMETER) * sin(DEGRESS_TO_RADIAN(30)) - \
			PHIL_DIAMETER / 2);											       \
	philX[1] = (int)((x) + DESK_DIAMETER /2 +									       \
			(DESK_DIAMETER / 2 + PHIL_DIAMETER) * cos(DEGRESS_TO_RADIAN(90)) - \
			PHIL_DIAMETER / 2);											       \
    philY[1] = (int)((y) + DESK_DIAMETER /2 -									       \
			(DESK_DIAMETER / 2 + PHIL_DIAMETER) * sin(DEGRESS_TO_RADIAN(90)) - \
			PHIL_DIAMETER / 2);											       \
	philX[2] = (int)((x) + DESK_DIAMETER /2 -									       \
			(DESK_DIAMETER / 2 + PHIL_DIAMETER) * cos(DEGRESS_TO_RADIAN(30)) - \
			PHIL_DIAMETER / 2);											       \
    philY[2] = (int)((y) + DESK_DIAMETER /2 -									       \
			(DESK_DIAMETER / 2 + PHIL_DIAMETER) * sin(DEGRESS_TO_RADIAN(30)) - \
			PHIL_DIAMETER / 2);											       \
	philX[3] = (int)((x) + DESK_DIAMETER /2 -									       \
			(DESK_DIAMETER / 2 + PHIL_DIAMETER) * cos(DEGRESS_TO_RADIAN(30)) - \
			PHIL_DIAMETER / 2);											       \
    philY[3] = (int)((y) + DESK_DIAMETER /2 +									       \
			(DESK_DIAMETER / 2 + PHIL_DIAMETER) * sin(DEGRESS_TO_RADIAN(30)) - \
			PHIL_DIAMETER / 2);											       \
	philX[4] = (int)((x) + DESK_DIAMETER /2 -									       \
			(DESK_DIAMETER / 2 + PHIL_DIAMETER) * cos(DEGRESS_TO_RADIAN(90)) - \
			PHIL_DIAMETER / 2);											       \
    philY[4] = (int)((y) + DESK_DIAMETER /2 +									       \
			(DESK_DIAMETER / 2 + PHIL_DIAMETER) * sin(DEGRESS_TO_RADIAN(90)) - \
			PHIL_DIAMETER / 2);											       \
	philX[5] = (int)((x) + DESK_DIAMETER /2 +									       \
			(DESK_DIAMETER / 2 + PHIL_DIAMETER) * cos(DEGRESS_TO_RADIAN(30)) - \
			PHIL_DIAMETER / 2);											       \
    philY[5] = (int)((y) + DESK_DIAMETER /2 +									       \
			(DESK_DIAMETER / 2 + PHIL_DIAMETER) * sin(DEGRESS_TO_RADIAN(30)) - \
			PHIL_DIAMETER / 2);

typedef struct
{
	HWND m_hWnd; //窗口句柄
	int chopXY[8]; //画筷子用得坐标
	int philX, philY; //哲学家的坐标
	int Id; //线程的编号
}PARAM;
	
const int DESK_DIAMETER = 200; //圆桌的直径
const int PHIL_DIAMETER = 30; //代表哲学家的圆的直径
const int CHOP_LENGHT = 50; //筷子的长度
const int PHIL_NUM = 6; //哲学家的个数
const int TIME = 10000; //模拟的运行时间

class CPhilosopherView : public CView
{
protected: // create from serialization only
	CPhilosopherView();
	DECLARE_DYNCREATE(CPhilosopherView)

// Attributes
public:
	CPhilosopherDoc* GetDocument();

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CPhilosopherView)
	public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	protected:
	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CPhilosopherView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CPhilosopherView)
	afx_msg void OnPlayOnce();
	afx_msg void OnPlayMany();
	afx_msg void OnUpdatePlayMany(CCmdUI* pCmdUI);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

private:
	CWinThread *m_pThread[6]; //产生线程的对象
};

#ifndef _DEBUG  // debug version in PhilosopherView.cpp
inline CPhilosopherDoc* CPhilosopherView::GetDocument()
   { return (CPhilosopherDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

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

#endif // !defined(AFX_PHILOSOPHERVIEW_H__47A6615C_3896_4F40_B28F_94B9BF9EDA4D__INCLUDED_)

⌨️ 快捷键说明

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