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

📄 checkdoc.cpp

📁 讲mfc的书
💻 CPP
字号:
// checkdoc.cpp : implementation of the CCheckerDoc class
//

#include "stdafx.h"
#include "checker.h"


#include "checkdoc.h"
#include "debugvw.h"


#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCheckerDoc

IMPLEMENT_DYNCREATE(CCheckerDoc, CDocument)

BEGIN_MESSAGE_MAP(CCheckerDoc, CDocument)
        //{{AFX_MSG_MAP(CCheckerDoc)
	ON_COMMAND(IDM_DEBUGWIN, OnDebugwin)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCheckerDoc construction/destruction

CCheckerDoc::CCheckerDoc() : m_statearray(8,8)
{
	    int x,y;
		m_selectflag=FALSE;
		for (y=0;y<3;y++)
		  for (x=!(y%2);x<8;x+=2)
		     m_statearray.SetAt(x,y,CELL_BLACK);
	 	for (y=5;y<8;y++)
		  for (x=!(y%2);x<8;x+=2)
        	m_statearray.SetAt(x,y,CELL_RED);
		movenum=0;
}

CCheckerDoc::~CCheckerDoc()
{
}

BOOL CCheckerDoc::OnNewDocument()
{
        if (!CDocument::OnNewDocument())
                return FALSE;

        // TODO: add reinitialization code here
        // (SDI documents will reuse this document)

        return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CCheckerDoc serialization

void CCheckerDoc::Serialize(CArchive& ar)
{
       if (ar.IsStoring())
	     ar<<(DWORD)movenum;
	   else
	     {
		 DWORD move;
		 ar>>move;
		 movenum=move;
		 }
       m_statearray.Serialize(ar);
	   
}

/////////////////////////////////////////////////////////////////////////////
// CCheckerDoc diagnostics

#ifdef _DEBUG
void CCheckerDoc::AssertValid() const
{
        CDocument::AssertValid();
}

void CCheckerDoc::Dump(CDumpContext& dc) const
{
        CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CCheckerDoc commands

STATE CCheckerDoc::CellState(int x,int y)
  {
  return m_statearray.GetAt(x,y);
  }			   

void CCheckerDoc::SetCellState(int x,int y,STATE s)
  {
  CPoint pt(x,y);
  m_statearray.SetAt(x,y,s);
  UpdateAllViews(NULL,(LPARAM)&pt);
  SetModifiedFlag();
  }

// Count cells -- if typ==CELL_RED count CELL_RED and CELL_REDKING
// if typ==CELL_BLACK count CELL_BLACK and CELL_BLACKKING 
int CCheckerDoc::Count(STATE typ)
  {
  int i,max=m_statearray.GetUpperBound(),ct=0;
  if (max==-1) return 0;
  for (i=0;i<=max;i++)
    {
	STATE s=m_statearray[i];
	if (typ==s) ct++;
	if (typ==CELL_RED && s==CELL_REDKING) ct++;
	if (typ==CELL_BLACK && s==CELL_BLACKKING) ct++;
	} 
  return ct;
  }


void CCheckerDoc::OnDebugwin() 
{
#if 1  // Easy way to make a new view -- use doc templates
    CMultiDocTemplate temptemplate(IDR_DEBUGTYPE,RUNTIME_CLASS(CCheckerDoc),
      RUNTIME_CLASS(CMDIChildWnd),RUNTIME_CLASS(DebugView));
	CFrameWnd *frame=temptemplate.CreateNewFrame(this,NULL);
	if (!frame)
	  AfxMessageBox("Can't create debug window");
	else
	  frame->InitialUpdateFrame(this,TRUE);
#else // hard way -- do all the work yourself
		CMDIChildWnd *frame=new CMDIChildWnd;
	if (!frame->Create(NULL,"Debug output: "+GetTitle()))
	  {
	  AfxMessageBox("Can't create debug window frame");
	  return;
	  }

	DebugView *view=new DebugView;
	// Don't care about size -- RecalcLayout will resize anyway.
	if (!view->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,CRect(0,0,0,0),frame,AFX_IDW_PANE_FIRST))
	  {
	  AfxMessageBox("Can't create debug window view");
	  frame->DestroyWindow();
	  }
	// add view to document (this)
    AddView(view);
	// Make sure OnInitialUpdate fires
	frame->InitialUpdateFrame(this,TRUE);
	// Layout frame
	frame->RecalcLayout();
#endif
}

⌨️ 快捷键说明

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