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

📄 drawinpdaview.cpp

📁 在PDA中的画图程序
💻 CPP
字号:
// DrawInPDAView.cpp : implementation of the CDrawInPDAView class
//

#include "stdafx.h"
#include "DrawInPDA.h"
#include "Tool.h"
#include "DrawInPDAView.h"
#include "DrawInPDADoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDrawInPDAView
CDrawInPDADoc* p_Doc;
CDrawInPDAView *p_View;

IMPLEMENT_DYNCREATE(CDrawInPDAView, CView)

BEGIN_MESSAGE_MAP(CDrawInPDAView, CView)
	//{{AFX_MSG_MAP(CDrawInPDAView)
	ON_WM_SIZE()
	ON_WM_LBUTTONDBLCLK()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_COMMAND_RANGE(ID_DRAW_POINT,ID_DRAW_MOVE,OnDrawShape)
    ON_UPDATE_COMMAND_UI_RANGE(ID_DRAW_POINT,ID_DRAW_MOVE,OnUpdateDrawCommand)
	//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDrawInPDAView construction/destruction

CDrawInPDAView::CDrawInPDAView()
{
	// TODO: add construction code here
	 m_xStart=0;
	 m_yStart=0;
	 blc=1.0;

}

CDrawInPDAView::~CDrawInPDAView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDrawInPDAView drawing

void CDrawInPDAView::OnDraw(CDC* pDC)
{
	CDrawInPDADoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	pDoc->Draw(pDC);

	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CDrawInPDAView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDrawInPDAView message handlers

void CDrawInPDAView::OnDrawShape(UINT m_nID)
{
	switch( m_nID )
	{
	case ID_DRAW_SELECT: CTool::c_CurrentTool = ttSelect; break;
	case ID_DRAW_POINT: CTool::c_CurrentTool = ttDrawPoint; break;
	case ID_DRAW_LINE: CTool::c_CurrentTool = ttDrawLine; break;
	case ID_DRAW_POLYGON: CTool::c_CurrentTool = ttDrawPolygon; break;
	case ID_DRAW_RECTANGLE: CTool::c_CurrentTool = ttDrawRectangle; break;
	case ID_DRAW_ZOOMIN: CTool::c_CurrentTool = ttZoomIn; break;
	case ID_DRAW_ZOOM: CTool::c_CurrentTool = ttZoom; break;
	case ID_DRAW_MOVE: CTool::c_CurrentTool = ttMove; break;
	default: break;
	}
	CString msg;
    //msg.Format("%s %d", "Test", m_nID);
	::AfxGetApp()->m_pMainWnd->SetWindowText(msg);

}

void CDrawInPDAView::OnUpdateDrawCommand(CCmdUI *pCmdUI)
{
		bool bFlag = false;

	switch (pCmdUI->m_nID)
	{
    case ID_DRAW_SELECT:
		if (CTool::c_CurrentTool == ttSelect)
			bFlag = true;
		break;
	case ID_DRAW_POINT: 
		if (CTool::c_CurrentTool == ttDrawPoint) 
			bFlag = true; 
		break;
	 case ID_DRAW_LINE: 
		if (CTool::c_CurrentTool == ttDrawLine)
			bFlag = true; 
		break;
	case ID_DRAW_POLYGON: 
		if (CTool::c_CurrentTool == ttDrawPolygon)
			bFlag = true; 
		break;
	case ID_DRAW_RECTANGLE: 
		if (CTool::c_CurrentTool == ttDrawRectangle)
			bFlag = true; 
		break;
	case ID_DRAW_ZOOMIN: 
		if (CTool::c_CurrentTool == ttZoomIn)
			bFlag = true; 
		break;   

	case ID_DRAW_ZOOM: 
		if (CTool::c_CurrentTool == ttZoom)
			bFlag = true; 
		break;
	case ID_DRAW_MOVE: 
		if (CTool::c_CurrentTool == ttMove)
			bFlag = true; 
		break;   
	default: break;
	}
	pCmdUI->SetCheck(bFlag);

}

BOOL CDrawInPDAView::OnSetCursor(CWnd *pWnd, UINT nHitTest, UINT message)
{
  return CView::OnSetCursor(pWnd, nHitTest, message);
}

void CDrawInPDAView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
{
	// TODO: Add your specialized code here and/or call the base class
	p_View=this;
	CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}

void CDrawInPDAView::OnSize(UINT nType, int cx, int cy) 
{
	
	m_wScreen=cx;	
	m_hScreen=cy;
	CView::OnSize(nType, cx, cy);
	// TODO: Add your message handler code here
	
}
void CDrawInPDAView::DPtoVP(float x,float y,int *X,int *Y)
{		*X=(int)((x-m_xStart)/blc);
//	if(m_MapMode==1)
		*Y=(int)((y-m_yStart)/blc);
//	else
//		*Y=(int)((y-m_yStart)*blc);	
	
}

void CDrawInPDAView::VPtoDP(int x,int y,float *X,float *Y)
{
	*X=m_xStart+x*blc;
//	if(m_MapMode==1)
	*Y=m_yStart+blc*y;
//	else
//	*Y=m_yStart+blc*(y+m_hScreen);


}

void CDrawInPDAView::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
		CTool* pTool = CTool::FindTool(CTool::c_CurrentTool);
	if (pTool != NULL)
		pTool->OnLButtonDblClk(this, nFlags, point);

	CView::OnLButtonDblClk(nFlags, point);
}

void CDrawInPDAView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CTool* pTool = CTool::FindTool(CTool::c_CurrentTool);
	if (pTool != NULL)
		pTool->OnLButtonDown(this, nFlags, point);
	
	CView::OnLButtonDown(nFlags, point);
}

void CDrawInPDAView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CTool* pTool = CTool::FindTool(CTool::c_CurrentTool);
	if (pTool != NULL)
		pTool->OnLButtonUp(this, nFlags, point);

	
	CView::OnLButtonUp(nFlags, point);
}

void CDrawInPDAView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CTool* pTool = CTool::FindTool(CTool::c_CurrentTool);
	if (pTool != NULL)
		pTool->OnMouseMove(this, nFlags, point);
	
	CView::OnMouseMove(nFlags, point);
}

⌨️ 快捷键说明

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