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

📄 ex6_1view.cpp

📁 C++程序设计源代码例
💻 CPP
字号:
// Ex6_1View.cpp : implementation of the CEx6_1View class
//

#include "stdafx.h"
#include "Ex6_1.h"

#include "Ex6_1Doc.h"
#include "Ex6_1View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CEx6_1View

IMPLEMENT_DYNCREATE(CEx6_1View, CView)

BEGIN_MESSAGE_MAP(CEx6_1View, CView)
	//{{AFX_MSG_MAP(CEx6_1View)
	ON_WM_LBUTTONDBLCLK()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEx6_1View construction/destruction

CEx6_1View::CEx6_1View()
{
	// TODO: add construction code here

}

CEx6_1View::~CEx6_1View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEx6_1View drawing

void CEx6_1View::OnDraw(CDC* pDC)
{
	CEx6_1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CRect Rect;	
	GetClientRect (Rect); //取得客户区	
	// 以客户区中心设置坐标原点	
	pDC->SetViewportOrg (Rect.Width ()/2,Rect.Height ()/2);	
	pDC->TextOut(-60,-10,pDoc->m_MouseMsg );//输出字符串 

	pDC->SetViewportOrg(0,0);//恢复坐标原点位置
	CPoint org;
	int i;
	if(pDoc->m_type) //m_type=1时画圆
	{  
		for(i=0;i<=pDoc->m_iPoint;i++ )
		{ 
			org=pDoc->m_PointArray[i];//取第i个图形的输出坐标
			pDC->Ellipse(org.x-10,org.y-10,org.x+10,org.y+10);//画圆
		}
	}
	else // m_type=0时画矩形
	{ 
		for(i=0;i<=pDoc->m_iPoint;i++ )
		{ 
			org=pDoc->m_PointArray[i];
			pDC->Rectangle(org.x-10,org.y-10,org.x+10,org.y+10);
		}
	}

}

/////////////////////////////////////////////////////////////////////////////
// CEx6_1View diagnostics

#ifdef _DEBUG
void CEx6_1View::AssertValid() const
{
	CView::AssertValid();
}

void CEx6_1View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CEx6_1View message handlers

void CEx6_1View::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CEx6_1Doc* pDoc = GetDocument();//获取文档指针	
	pDoc->m_iPoint++;//文档类变量m_iPoint增1	
	//在数组m_PointArray中记录当前鼠标双击的坐标	
	pDoc->m_PointArray[pDoc->m_iPoint]=point;	
	this->Invalidate(); //更新视图

	CView::OnLButtonDblClk(nFlags, point);
}

⌨️ 快捷键说明

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