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

📄 myscrollview.cpp

📁 一个非常好的GPS应用软件
💻 CPP
字号:
// MyScrollView.cpp : implementation file
//

#include "stdafx.h"
#include "GpsNav.h"
#include "MyScrollView.h"
#include "GpsNavDoc.h"

void Marker(LONG x, LONG y, HDC hdc);
CPoint CoordTranstport(double x,double y);

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

/////////////////////////////////////////////////////////////////////////////
// CMyScrollView

IMPLEMENT_DYNCREATE(CMyScrollView, CScrollView)

CMyScrollView::CMyScrollView()
{
}

CMyScrollView::~CMyScrollView()
{
}


BEGIN_MESSAGE_MAP(CMyScrollView, CScrollView)
	//{{AFX_MSG_MAP(CMyScrollView)
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	ON_WM_ERASEBKGND()
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyScrollView drawing

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

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx=1000; 
	sizeTotal.cy =1200;
	
	SetScrollSizes(MM_TEXT, sizeTotal);

	
	SetScrollPos(SB_HORZ,0,TRUE);
	SetScrollPos(SB_VERT,600,TRUE);
	Invalidate(TRUE);
	UpdateWindow();	

}

void CMyScrollView::OnDraw(CDC* pDC)
{
		CMyGpsNavDoc * pDoc =(CMyGpsNavDoc* ) GetDocument();
		// TODO: add draw code here
		CBitmap bmp;
		bmp.LoadBitmap(img);
		CClientDC pdc(this);
		OnPrepareDC(&pdc);
		CDC mDC;
		mDC.CreateCompatibleDC(&pdc);
		mDC.SelectObject(&bmp);
		BITMAP bmpinfo;
		//
		bmp.GetBitmap(&bmpinfo);
		CRect r(0,0,bmpinfo.bmWidth,bmpinfo.bmHeight);
		pdc.DPtoLP(&r);
		r.OffsetRect(100,50);
		pdc.BitBlt(0,0,r.Size().cx,r.Size().cy,&mDC,0,0,SRCCOPY);	

		CPoint cp;
		cp=pDoc->pt;
		Marker(cp.x, cp.y,pDC->m_hDC);

		
	//得到视图的无效矩形
	/*
		CRect rectClip;
	CRect rectStroke;
	pDC->GetClipBox(&rectClip);
	pDC->LPtoDP(&rectClip);
	rectClip.InflateRect(1, 1); 
	*/

	CTypedPtrList<CObList,CStroke*>& strokeList = pDoc->m_strokeList;
	POSITION pos = strokeList.GetHeadPosition();
	while (pos != NULL)
	{
		CStroke* pStroke = strokeList.GetNext(pos);
		/*
		rectStroke = pStroke->GetBoundingRect();
		pDC->LPtoDP(&rectStroke);
		rectStroke.InflateRect(1, 1); 
		if (!rectStroke.IntersectRect(&rectStroke, &rectClip))//判断两矩形的交际是否为空
			continue;
		*/
		if(pStroke->m_pointArray.GetSize()>0)
		{
			pStroke->DrawStroke(pDC);   //画线
		}
	}


}

/////////////////////////////////////////////////////////////////////////////
// CMyScrollView diagnostics

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

void CMyScrollView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyScrollView message handlers

//DEL BOOL CMyScrollView::OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll) 
//DEL {
//DEL 	// TODO: Add your specialized code here and/or call the base class
//DEL 	
//DEL 	return CScrollView::OnScroll(nScrollCode, nPos, bDoScroll);
//DEL }

void CMyScrollView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	pDC->SetMapMode(MM_ANISOTROPIC);
	CPoint cPorg(GetScrollPos(SB_HORZ),GetScrollPos(SB_VERT));
	pDC->SetViewportOrg(-cPorg);
	CScrollView::OnPrepareDC(pDC, pInfo);
}


void CMyScrollView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	if (GetCapture() != this)
	{
		return; //如果该视图没有俘获鼠标,那么不在该区域绘制
	}

	HCURSOR hCursor;
	hCursor = AfxGetApp()->LoadCursor(IDC_MYCURSOR);
	SetCursor(hCursor);

	m_ptPrev = point;	
}



void CMyScrollView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	if (GetCapture() != this)
		return; //

	//m_ptPrev = point;  
	ReleaseCapture();   //
}

BOOL CMyScrollView::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	return TRUE;
	//return CScrollView::OnEraseBkgnd(pDC);
}

void CMyScrollView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default	
	SetCapture();       
	m_ptPrev = point;  	
	CScrollView::OnLButtonDown(nFlags, point);
}

BOOL CMyScrollView::OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll) 
{
	// TODO: Add your specialized code here and/or call the base class
	Invalidate();	
	return CScrollView::OnScroll(nScrollCode, nPos, bDoScroll);
}

⌨️ 快捷键说明

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