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

📄 nqueenview.cpp

📁 该问题是十九世纪著名的数学家高斯1850年提出
💻 CPP
字号:
// nqueenView.cpp : implementation of the CNqueenView class
//

#include "stdafx.h"
#include "nqueen.h"

#include "nqueenDoc.h"
#include "nqueenView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CNqueenView

IMPLEMENT_DYNCREATE(CNqueenView, CScrollView)

BEGIN_MESSAGE_MAP(CNqueenView, CScrollView)
	//{{AFX_MSG_MAP(CNqueenView)
	ON_WM_HSCROLL()
	ON_WM_VSCROLL()
	ON_COMMAND(ID_BUTTON_RUN, OnButtonRun)
	ON_COMMAND(ID_BUTTON_BACK, OnButtonBack)
	ON_UPDATE_COMMAND_UI(ID_BUTTON_BACK, OnUpdateButtonBack)
	ON_COMMAND(ID_BUTTON_NEXT, OnButtonNext)
	ON_UPDATE_COMMAND_UI(ID_BUTTON_NEXT, OnUpdateButtonNext)
	ON_COMMAND(ID_BUTTON_ADD, OnButtonAdd)
	ON_UPDATE_COMMAND_UI(ID_BUTTON_ADD, OnUpdateButtonAdd)
	ON_COMMAND(ID_BUTTON_SUB, OnButtonSub)
	ON_UPDATE_COMMAND_UI(ID_BUTTON_SUB, OnUpdateButtonSub)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CNqueenView construction/destruction

CNqueenView::CNqueenView()
{
	// TODO: add construction code here
	m_strtitle = "N皇后问题动态演示";
	m_icount = 4;
	m_pqueen = new Cqueen(m_icount);

}

CNqueenView::~CNqueenView()
{
	delete m_pqueen;
}

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

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CNqueenView drawing

void CNqueenView::OnDraw(CDC* pDC)
{
	CNqueenDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
	m_pqueen->drawqueenn(pDC);
}

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

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

/////////////////////////////////////////////////////////////////////////////
// CNqueenView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CNqueenView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CNqueenView message handlers

void CNqueenView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	Invalidate();
	CScrollView::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CNqueenView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	Invalidate();
	CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
}

UINT computeplace(LPVOID pParam)
{
	CNqueenView* view = (CNqueenView *)pParam;
	view->m_pqueen->computqueenplace(0 , view);
	CString msg;
	msg.Format("N皇后问题动态演示 共计算有%d个结果" , view->m_pqueen->getlistsize());
	::AfxGetMainWnd()->SetWindowText(msg);
	return 0;
}

void CNqueenView::OnButtonRun() 
{
	// TODO: Add your command handler code here
	AfxBeginThread(computeplace, (LPVOID)this);
}

void CNqueenView::OnButtonBack() 
{
	// TODO: Add your command handler code here
	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);
	Invalidate();
}

void CNqueenView::OnUpdateButtonBack(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(m_pqueen->getdrawindex()>-1);
}

void CNqueenView::OnButtonNext() 
{
	// TODO: Add your command handler code here
	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);
	Invalidate();
}

void CNqueenView::OnUpdateButtonNext(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(m_pqueen->getdrawindex() < m_pqueen->getlistsize() - 1);
}

void CNqueenView::OnButtonAdd() 
{
	// TODO: Add your command handler code here
	if (m_icount < 5 )
	{
		m_pqueen->setrow(++m_icount);
	}
	Invalidate();
	CString msg;
	msg.Format("%d皇后问题动态演示" , m_icount);
	::AfxGetMainWnd()->SetWindowText(msg);
	SetScrollSizes(MM_TEXT, m_pqueen->getqueengridsize());//确定扩展的宽度
}

void CNqueenView::OnUpdateButtonAdd(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(m_icount<15);
}

void CNqueenView::OnButtonSub() 
{
	// TODO: Add your command handler code here
	if (m_icount > 4 )
	{
		m_pqueen->setrow(--m_icount);
	}
	Invalidate();
	CString msg;
	msg.Format("%d皇后问题动态演示" , m_icount);
	::AfxGetMainWnd()->SetWindowText(msg);
	SetScrollSizes(MM_TEXT, m_pqueen->getqueengridsize());
}

void CNqueenView::OnUpdateButtonSub(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(m_icount > 4);
}

⌨️ 快捷键说明

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