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

📄 bmpview.cpp

📁 在一个bmp格式的地图上根据GPS信号定位
💻 CPP
字号:
// bmpView.cpp : implementation of the CBmpView class
//

#include "stdafx.h"
#include "bmp.h"

#include "bmpDoc.h"
#include "bmpView.h"
#include "Param.h"
#include "Coor.h"

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


double xx, xy, yx, yy, xk, yk, cx, cy;


/////////////////////////////////////////////////////////////////////////////
// CBmpView

IMPLEMENT_DYNCREATE(CBmpView, CView)

BEGIN_MESSAGE_MAP(CBmpView, CView)
	//{{AFX_MSG_MAP(CBmpView)
	ON_COMMAND(ID_SPLIT, OnSplit)
	ON_WM_KEYDOWN()
	ON_WM_LBUTTONDBLCLK()
	ON_COMMAND(ID_DISPCOOR, OnDispcoor)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBmpView construction/destruction

CBmpView::CBmpView()
{
	// TODO: add construction code here
	stX = 0;
	stY = 0;
	xx	= 0;
	xy	= 0;
	yx	= 0;
	yy	= 0;
	cx	= 0;
	cy	= 0;
}

CBmpView::~CBmpView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CBmpView drawing

void CBmpView::OnDraw(CDC* pDC)
{
	CBmpDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data her
	RECT win;
	GetWindowRect(&win);
	FitStartXY();
	pDoc->cbs.Draw(pDC, stX, stY, RECTWIDTH(&win), RECTHEIGHT(&win));
}

/////////////////////////////////////////////////////////////////////////////
// CBmpView printing

BOOL CBmpView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CBmpView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CBmpView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CBmpView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CBmpView message handlers

void CBmpView::OnSplit() 
{
	// TODO: Add your command handler code here
	CParam cp;
	CBmpDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	cp.SetBmp(&pDoc->cbs);
	
	cp.DoModal();
}


void CBmpView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	int flag = 1;
	switch(nChar)
	{
	case VK_LEFT:
		icx -= 10;
		break;
	case VK_RIGHT:
		icx += 10;
		break;
	case VK_UP:
		icy -= 10;
		break;
	case VK_DOWN:
		icy += 10;
		break;
	default:
		flag = 0;
		break;
	}
	if(flag)
	{
		CClientDC dc(this);
		OnDraw(&dc);
	}
	CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CBmpView::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CString str;
	double tmp = xx * yy - xy * yx;
	str.Format("屏幕坐标:(%4d, %4d)\n图像坐标:(%4d, %4d)\n" +
		CString("经度坐标:%lf\n纬度坐标:%lf\n"),
		point.x, point.y,
		point.x + stX, point.y + stY,
		(yy * (point.x + stX - xk) - xy * (point.y + stY - yk)) / tmp,
		(xx * (point.y + stY - yk) - yx * (point.x + stX - xk)) / tmp);
	MessageBox(str, "坐标");
	CView::OnLButtonDblClk(nFlags, point);
}

void CBmpView::OnDispcoor() 
{
	// TODO: Add your command handler code here
	CCoor cc;
	if(cc.DoModal() == IDOK)
	{
		cx = cc.m_e;
		cy = cc.m_n;
		
		icx = (int)(xx * cx + xy * cy + xk);
		icy = (int)(yx * cx + yy * cy + yk);
		
		CClientDC dc(this);
		OnDraw(&dc);

		KillTimer(0);
		SetTimer(0, 250, NULL);
	}
}

void CBmpView::FitStartXY()
{
	CBmpDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	int w = pDoc->cbs.GetWidth();
	int h = pDoc->cbs.GetHeight();
	RECT win;
	int winw, winh;
	GetWindowRect(&win);
	winw = RECTWIDTH(&win);
	winh = RECTHEIGHT(&win);

	if(icx - stX > winw * 3 / 4)
		stX = icx - winw * 3 / 4;
	else if(icx < stX + winw / 4)
		stX = icx - winw / 4;
	if(icy - stY > winh * 3 / 4)
		stY = icy - winh * 3 / 4;
	else if(icy < stY + winh / 4)
		stY = icy - winh / 4;

	if(stX < 0) stX = 0;
	if(stY < 0) stY = 0;
	if(w > winw && stX > w - winw) stX = w - winw;
	if(h > winh && stY > h - winh) stY = h - winh;
}

void CBmpView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	static int what = 0;
	CClientDC dc(this);
	CBmpDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if(what == 0)
		pDoc->cbs.Drawm(&dc, icx - stX, icy - stY);
	else
		pDoc->cbs.Drawr(&dc, icx - stX, icy - stY, icx, icy);
	what = 1 - what;
	CView::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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