1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
//ticStatic_drv.cpp
int ticStatic_drv::m_iTurn;
//int ticStatic_drv::m_iStatusInfo[9];
/////////////////////////////////////////////////////////////////////////////
// ticStatic_drv
ticStatic_drv::ticStatic_drv()
{
m_bCross = 0;
}
ticStatic_drv::~ticStatic_drv()
{
}
BEGIN_MESSAGE_MAP(ticStatic_drv, CStatic)
//{{AFX_MSG_MAP(ticStatic_drv)
ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ticStatic_drv message handlers
//how to catch a click on controls...
void ticStatic_drv::OnClicked()
{
//if game hasnt started, return
if(!CTicDlg::m_bGameStarted)
{
MessageBox("Start the game first from menu!!");
return;
}
if(!m_bCross)
{
m_iTurn++;
// m_bCross = (m_iTurn % 2) == 0 ? CIRCLE : CROSS; //used when two players playing
m_bCross = CROSS; //when playing with computer, its always cross
RedrawWindow();
GetParent()->SendMessage(WM_UPDATEINFO,0,0);
}
}
void ticStatic_drv::OnPaint()
{
CPaintDC dc(this);
RECT rect;
if(m_bCross == CROSS)
{
HPEN hPen = CreatePen(PS_SOLID,2,RGB(0,0,255));
SelectObject(dc,hPen);
GetClientRect(&rect);
dc.MoveTo(0,0);
dc.LineTo(rect.right,rect.bottom);
dc.MoveTo(rect.right,0);
dc.LineTo(0,rect.bottom);
DeleteObject(hPen);
}
if(m_bCross == CIRCLE)
{
HPEN hPen = CreatePen(PS_SOLID,2,RGB(0,0,255));
HBRUSH hBrush = CreateSolidBrush(RGB(255,0,255));
SelectObject(dc,hPen);
SelectObject(dc,hBrush);
GetClientRect(&rect);
dc.Ellipse(rect.left + 5,rect.top + 5,rect.right - 5,rect.bottom - 5);
}
}
|