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

📄 drawformview.cpp

📁 是MFCfaq的一本书的源代码
💻 CPP
字号:
// DrawFormView.cpp : implementation file
//

#include "stdafx.h"
#include "OwnCaption.h"

#include "DrawDoc.h"

#include "DrawFormView.h"


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

/////////////////////////////////////////////////////////////////////////////
// CDrawFormView

IMPLEMENT_DYNCREATE(CDrawFormView, CFormView)

CDrawFormView::CDrawFormView()
	: CFormView(CDrawFormView::IDD)
{
	//{{AFX_DATA_INIT(CDrawFormView)
	m_nX = 0;
	m_nY = 0;
	m_nShape = -1;
	//}}AFX_DATA_INIT
}

CDrawFormView::~CDrawFormView()
{
}

void CDrawFormView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDrawFormView)
	DDX_Text(pDX, IDC_X, m_nX);
	DDX_Text(pDX, IDC_Y, m_nY);
	DDX_CBIndex(pDX, IDC_SHAPE, m_nShape);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDrawFormView, CFormView)
	//{{AFX_MSG_MAP(CDrawFormView)
	ON_BN_CLICKED(IDC_APPLY, OnApply)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDrawFormView diagnostics

#ifdef _DEBUG
void CDrawFormView::AssertValid() const
{
	CFormView::AssertValid();
}

void CDrawFormView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CDrawFormView message handlers

void CDrawFormView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// 1 - Get the current data from our document
	CDrawDoc* pDoc = GetDocument();

	m_nX = pDoc->m_point.x;
	m_nY = pDoc->m_point.y;

	switch( pDoc->m_shape )
	{
	default :
		ASSERT( FALSE );	// This should never happen !
		break;

	case CDrawDoc::SQUARE :
		m_nShape = 0;
		break;

	case CDrawDoc::CIRCLE :
		m_nShape = 1;
		break;
	}

	// 2 - Show the current data in our controls
	UpdateData( FALSE );
}

void CDrawFormView::OnApply() 
{
	// 1 - Get the data from our controls
	UpdateData( TRUE );

	// 2 - Update the document state
	CDrawDoc* pDoc = GetDocument();

	pDoc->m_point.x = m_nX;
	pDoc->m_point.y = m_nY;

	switch( m_nShape )
	{
	default:
		ASSERT( FALSE );		// This should never happen !
		break;

	case 0:
		pDoc->m_shape = CDrawDoc::SQUARE;
		break;

	case 1:
		pDoc->m_shape = CDrawDoc::CIRCLE;
		break;
	}

	// 3 - Tell the document something happened
	pDoc->SetModifiedFlag( TRUE );

	// 4 - Synchronize all other views
	pDoc->UpdateAllViews( this );
}

⌨️ 快捷键说明

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