?? nqueenview.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 + -