?? mainfrm.cpp
字號:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "MyChess.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_TIMER()
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
CRect rect(0,0,650,600);
if (cx!=800||cy!=600)
{
CalcWindowRect(&rect);
SetWindowPos(NULL,220,0,rect.Width(),rect.Height(),SWP_SHOWWINDOW);
}
}
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rect(0,0,900,980);
/*
MINMAXINFO MMI;
OnGetMinMaxInfo(&MMI);*/
CalcWindowRect(&rect);
SetWindowPos(NULL,220,0,rect.Width(),rect.Height(),SWP_SHOWWINDOW);
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) )
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
Timer1 = new CBTime;
Timer2 = new CBTime;
// TODO: Delete these three lines if you don't want the toolbar to be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
// CMainFrame message handlers
void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CFrameWnd::OnTimer(nIDEvent);
doc=(CMyChessDoc*)GetActiveDocument();
CDC *cdc=::AfxGetMainWnd()->GetDC();
switch(nIDEvent)
{
case 1:
if (doc->m_nWhoPlayNow==1)
{
if (Timer1->BLimit_1s==0 && Timer1->BLimit_0s==0 && Timer1->Bflag==false)
{
Timer1->Limit_0s++;
}
if (Timer1->Bflag==true)
{
if (Timer1->Bdelay==false)
{
Timer1->BLimit_1s=5;
Timer1->BLimit_0s=9;
}
if (Timer1->Bdelay==true && Timer1->flag==true)
{
Timer1->BLimit_0s--;
}
if (Timer1->BLimit_0s<0)
{
if (Timer1->BLimit_1s>=0)
{
Timer1->BLimit_1s--;
Timer1->BLimit_0s=9;
}
if(Timer1->BLimit_1s<0 && Timer1->flag==true)
{
Timer1->flag=false;
Timer1->BLimit_0s=0;
Timer1->BLimit_1s=0;
AfxMessageBox("You lose the game!");
}
}
Timer1->Bdelay=true;
}
Timer1->DrawTime(cdc,300);
Timer2->DrawTime(cdc,0);
Timer2->Bdelay=false;
}
break;
case 2:
if (doc->m_nWhoPlayNow==2)
{
if (Timer2->BLimit_1s==0 && Timer2->BLimit_0s==0 && Timer2->Bflag==false)
{
Timer2->Limit_0s++;
}
if (Timer2->Bflag==true)
{
if (Timer2->Bdelay==false)
{
Timer2->BLimit_1s=5;
Timer2->BLimit_0s=9;
}
if (Timer2->Bdelay==true && Timer2->flag==true)
{
Timer2->BLimit_0s--;
}
if (Timer2->BLimit_0s<0)
{
if (Timer2->BLimit_1s>=0)
{
Timer2->BLimit_1s--;
Timer2->BLimit_0s=9;
}
if(Timer2->BLimit_1s<0 && Timer2->flag==true)
{
Timer2->flag=false;
Timer2->BLimit_0s=0;
Timer2->BLimit_1s=0;
AfxMessageBox("You lose the game!");
}
}
Timer2->Bdelay=true;
}
Timer1->DrawTime(cdc,300);
Timer2->DrawTime(cdc,0);
Timer1->Bdelay=false;
}
break;
default:
break;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -