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

📄 eight_queenview.cpp

📁 Visual C++解决八皇后问题
💻 CPP
字号:
// Eight_QueenView.cpp : implementation of the CEight_QueenView class
//

#include "stdafx.h"
#include "Eight_Queen.h"

#include "Eight_QueenDoc.h"
#include "Eight_QueenView.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEight_QueenView

IMPLEMENT_DYNCREATE(CEight_QueenView, CScrollView)

BEGIN_MESSAGE_MAP(CEight_QueenView, CScrollView)
	//{{AFX_MSG_MAP(CEight_QueenView)
	ON_COMMAND(ID_VIEW_RUN, OnRun)
	ON_COMMAND(ID_VIEW_UP, OnUp)
	ON_COMMAND(ID_VIEW_DOWN, OnDown)
	ON_UPDATE_COMMAND_UI(ID_VIEW_UP, OnUpdateUp)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEight_QueenView construction/destruction

CEight_QueenView::CEight_QueenView()
{
 	m_strTitle = "八皇后问题动态演示";
	m_iCount = 8;
	m_pQueen = new CQueen(m_iCount);
	flage=false;
	
	

	
}

CEight_QueenView::~CEight_QueenView()
{
	delete m_pQueen;


}

BOOL CEight_QueenView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEight_QueenView drawing

void CEight_QueenView::OnDraw(CDC* pDC)
{
	CEight_QueenDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
		m_pQueen->DrawQueenN(pDC);
}

void CEight_QueenView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);
	

}

/////////////////////////////////////////////////////////////////////////////
// CEight_QueenView printing

BOOL CEight_QueenView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CEight_QueenView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CEight_QueenView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CEight_QueenView diagnostics

#ifdef _DEBUG
void CEight_QueenView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CEight_QueenView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CEight_QueenDoc* CEight_QueenView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEight_QueenDoc)));
	return (CEight_QueenDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CEight_QueenView message handlers

UINT ComputePlace(LPVOID pParam)
{
	CEight_QueenView* view = (CEight_QueenView *)pParam;
	view->m_pQueen->ComputQueenPlace(0 , view);
	CString msg;
	msg.Format("八皇后问题动态演示 共计算有%d个结果" , view->m_pQueen->GetListSize());
	::AfxGetMainWnd()->SetWindowText(msg);
	return 0;
}

void CEight_QueenView::OnRun() 
{

	AfxBeginThread(ComputePlace, (LPVOID)this);
	
}

void CEight_QueenView::OnUp() 
{
	m_pQueen->DrawList(m_pQueen->GetDrawIndex() - 1);
	m_strTitle.Format("%d皇后问题动态演示 共计算有%d个结果 当前显示第%d个" , m_iCount , m_pQueen->GetListSize() , m_pQueen->GetDrawIndex() + 1);
	AfxGetMainWnd()->SetWindowText(m_strTitle);
	int num=m_pQueen->GetDrawIndex()-1;
	if (num==-1)
	{
		flage=false;
	}
	Invalidate();
	
}

void CEight_QueenView::OnDown() 
{
	
	
	
	m_pQueen->DrawList(m_pQueen->GetDrawIndex() + 1);
	m_strTitle.Format("%d皇后问题动态演示 共计算有%d个结果 当前显示第%d个" , m_iCount , m_pQueen->GetListSize() , m_pQueen->GetDrawIndex() + 1);
	AfxGetMainWnd()->SetWindowText(m_strTitle);
	int num=m_pQueen->GetDrawIndex()+1;
	if (num==1)
	{
		flage=false;
	}
	else
	{
		flage=true;
	}
	Invalidate();
	
}


void CEight_QueenView::OnUpdateUp(CCmdUI* pCmdUI) 
{
	if(flage)
		pCmdUI->Enable(1); 
	else 
		pCmdUI->Enable(0);

	
}

⌨️ 快捷键说明

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