哲学家就餐问题――MFC演示程序(六)

2014-11-24 12:17:24 · 作者: · 浏览: 11
rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);//单行居中
}


//计算叉子的起始坐标和终止
for (i=0;i<6;i++)
{

pt_chopstick_start[i].x=pt_table.x-radius_table*sin(i*x+pi/6);
pt_chopstick_start[i].y=pt_table.y-radius_table*cos(i*x+pi/6);

pt_chopstick_end[i].x=pt_table.x-25*sin(i*x+pi/6);
pt_chopstick_end[i].y=pt_table.y-25*cos(i*x+pi/6);

}

//画筷子
CPen pen(PS_SOLID,4,RGB(0,0,0));
pDC->SelectObject(&pen);
for (i=0;i<6;i++)
{
pDC->MoveTo(pt_chopstick_start[i]);
pDC->LineTo(pt_chopstick_end[i]);
}
}
上述代码中的相关变量在CPhilosophy_EatingDlg中声明:

[cpp] class CPhilosophy_EatingDlg : public CDialog
{
// Construction
public:
CPhilosophy_EatingDlg(CWnd* pParent = NULL); // standard constructor
public:
ImageInfo imageinfo[6];
CWinThread *pthread[6];
CPoint pt_table;
CPoint pt_chair[6];
double radius_table;
double radius_chair;
CPoint pt_chopstick_start[6];
CPoint pt_chopstick_end[6];
//CPoint pt_chopstick_start[6];

BOOL m_continue;
class CPhilosophy_EatingDlg : public CDialog
{
// Construction
public:
CPhilosophy_EatingDlg(CWnd* pParent = NULL); // standard constructor
public:
ImageInfo imageinfo[6];
CWinThread *pthread[6];
CPoint pt_table;
CPoint pt_chair[6];
double radius_table;
double radius_chair;
CPoint pt_chopstick_start[6];
CPoint pt_chopstick_end[6];
//CPoint pt_chopstick_start[6];

BOOL m_continue;[cpp] 进程运行时图形变化的绘制已经在进程函数Eat中了,大家可以自己看下,不是很复杂。

三、两个按钮的代码

开始和停止按钮的代码,没什么内容,我把代码贴下,大家可以参考~

void CPhilosophy_EatingDlg::OnButtonStart()  
{
// TODO: Add your control notification handler code here
for (int m=0;m<6;m++)
{
chopsticks[m]=1;
}


for(int i=0;i<6;i++)
{
switch(i)
{
case 0:
imageinfo[i].edit=GetDlgItem(IDC_EDIT_STATE1)->m_hWnd;
break;
case 1:
imageinfo[i].edit=GetDlgItem(IDC_EDIT_STATE2)->m_hWnd;
break;
case 2:
imageinfo[i].edit=GetDlgItem(IDC_EDIT_STATE3)->m_hWnd;
break;
case 3:
imageinfo[i].edit=GetDlgItem(IDC_EDIT_STATE4)->m_hWnd;
break;
case 4:
imageinfo[i].edit=GetDlgItem(IDC_EDIT_STATE5)->m_hWnd;
break;
case 5:
imageinfo[i].edit=GetDlgItem(IDC_EDIT_STATE6)->m_hWnd;
break;
default:
break;
}
imageinfo[i].pWnd=this;

imageinfo[i].index=i;
imageinfo[i].pt_chair=pt_chair[i];
imageinfo[i].pt_chopstick_middle[0]=pt_chopstick_start[i];
imageinfo[i].pt_chopstick_middle[1]=pt_chopstick_start[(i+5)%6];
imageinfo[i].radius_chair=radius_chair;
imageinfo[i].radius_table=radius_table;
imageinfo[i].pt_chopstick_end[0]=pt_chopstick_end[i];
imageinfo[i].pt_chopstick_end[1]=pt_chopstick_end[(i+5)%6];
pthread[i]=AfxBeginThread(Eat,&imageinfo[i]);
}



}

void CPhilosophy_EatingDlg::OnButtonStop()
{
// TODO: Add your control notification handler code here
if (FALSE==m_continue)
{
GetDlgItem(IDC_BUTTON_STOP)->SetWindowText("继续演示");