📄 myview.cpp
字号:
// MyView.cpp : implementation file
//
#include "stdafx.h"
//#include " \ add additional includes here"
#include "MyView.h"
#include "MyDoc.h"
#include "Resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define MM_NON 0
#define MM_ZOOMPAN 101
#define MM_DZOOMIN 102
/////////////////////////////////////////////////////////////////////////////
// CMyView
IMPLEMENT_DYNCREATE(CMyView, CView)
CMyView::CMyView()
{
m_bHaveMouseRight=FALSE;
m_bOrientImg = FALSE;
m_LDown = FALSE;
m_LookMode = MM_NON;
m_Scale = 1.0f;
m_bHaveMouseRight = FALSE;
//m_CURRENTCURSOR = IDC_CROSS_CURSOR;
m_bNeedUpdate = FALSE;
m_zoomEnable = TRUE;
}
CMyView::~CMyView()
{
}
BEGIN_MESSAGE_MAP(CMyView, CView)
//{{AFX_MSG_MAP(CMyView)
ON_MESSAGE(MYWM_USER_LOST_MOUSERIGHT, OnLostMouse)
ON_WM_PAINT()
ON_WM_SETCURSOR()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_COMMAND(ID_DRAW_DZOOMIN, OnDrawDzoomin)
ON_COMMAND(ID_DRAW_REFRESH, OnDrawRefresh)
ON_COMMAND(ID_DRAW_ZOOMIN, OnDrawZoomin)
ON_COMMAND(ID_DRAW_ZOOMNON, OnDrawZoomnon)
ON_COMMAND(ID_DRAW_ZOOMOUT, OnDrawZoomout)
ON_COMMAND(ID_DRAW_ZOOMPAN, OnDrawZoompan)
ON_COMMAND(ID_ZOOM_FULLEXTENT, OnZoomFullextent)
ON_COMMAND(ID_ZOOM_NORMAL, OnZoomNormal)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyView drawing
void CMyView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
CView::OnDraw(pDC);
}
/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics
#ifdef _DEBUG
void CMyView::AssertValid() const
{
CView::AssertValid();
}
void CMyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers
BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
ASSERT(cs.style & WS_CHILD);
if (cs.lpszClass == NULL) //避免光标闪烁
cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS);
return TRUE;
return CView::PreCreateWindow(cs);
}
LRESULT CMyView::OnLostMouse(WPARAM wParam, LPARAM lParam)
{
m_bHaveMouseRight = FALSE;
return TRUE;
}
LRESULT CMyView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if(message == WM_PAINT ||(message >= 0x0200 && message <= 0x0209) ||
(message >= 0x0100 && message <= 0x0109) ||
message >= WM_USER +1 && message <= WM_USER + 300)
((CMyDoc*)GetDocument())->WindowProc(message, wParam, lParam);
return CView::WindowProc(message, wParam, lParam);
}
void CMyView::OnMyDraw(CDC* pDC)
{
//do nothing
}
void CMyView::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
CBrush br;
CBrush *oldBr;
br.CreateSolidBrush(RGB(255,255,255));
GetClientRect(&rect);
oldBr=dc.SelectObject(&br);
dc.FillRect(&rect,&br);
dc.SelectObject(oldBr);
}
BOOL CMyView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
if(nHitTest == HTCLIENT)
{
// m_CURRENTCURSOR = 32514;//IDC_WAIT;
SetCursor(m_hCursor);
return TRUE;
}
return CView::OnSetCursor(pWnd, nHitTest, message);
}
void CMyView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/* if ( nFlags == MK_COORDINATE ) //zxy 99.06.23
{
CPoint p = *((CPoint *)(MAKELONG(point.x,point.y)));
point = p;
MapToClient(point);
}*/
CView::OnRButtonDown(nFlags, point);
}
void CMyView::OnRButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CView::OnRButtonUp(nFlags, point);
}
void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(!m_LDown | !m_bHaveMouseRight )
return;
if(m_LookMode == MM_DZOOMIN)
{
CClientDC dc(this);
return;
}
if(m_LookMode == MM_ZOOMPAN )
{
//mousemove
CRect client;
GetClientRect(client);
}
//m_OldPos = point;
CView::OnMouseMove(nFlags, point);
}
void CMyView::OnLButtonUp(UINT nFlags, CPoint point)
{
if(!m_bHaveMouseRight)return;
ReleaseCapture();
if(m_LDown == FALSE)
return;
else
m_LDown = FALSE;
/*
if(m_LookMode == )
{
CPoint center = point;
ClientToMap(center);
m_Scale *= 2;
PointZoom(center,m_Scale);
}
*/
if(m_LookMode == MM_DZOOMIN)
{
CClientDC dc(this);
}
if(m_LookMode == MM_ZOOMPAN )
{
}
if(m_bOrientImg)
{
m_LookMode = MM_NON;
//m_CURRENTCURSOR = IDC_CROSS_CURSOR;
m_hCursor = AfxGetApp()->LoadCursor(IDC_CROSS_CURSOR);
}
CView::OnLButtonUp(nFlags, point);
}
void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(!m_bHaveMouseRight)return;
m_LDown = TRUE;
m_OldPos = point;
if(m_LookMode == MM_DZOOMIN)
{
SetCapture();
}
else if(m_LookMode == MM_ZOOMPAN )
{
SetCapture();
}
CView::OnLButtonDown(nFlags, point);
}
void CMyView::OnDrawDzoomin()
{
// TODO: Add your command handler code here
//GetMouseRight();
SendMessage(MYWM_USER_LOST_MOUSERIGHT);
m_bHaveMouseRight = TRUE;
//m_CURRENTCURSOR = IDC_ZOOMINCURSOR;
m_hCursor = AfxGetApp()->LoadCursor(IDC_ZOOMINCURSOR);
m_LookMode = MM_DZOOMIN;
//MM_DZOOMIN
}
void CMyView::OnDrawRefresh()
{
// TODO: Add your command handler code here
m_bNeedUpdate = TRUE;
Invalidate();
}
void CMyView::OnDrawZoomin()
{
// TODO: Add your command handler code here
CPoint center;
}
void CMyView::OnDrawZoomnon()
{
// TODO: Add your command handler code here
//m_CURRENTCURSOR = IDC_CROSS_CURSOR;
m_hCursor = AfxGetApp()->LoadCursor(IDC_CROSS_CURSOR);
m_LookMode = MM_NON;
}
void CMyView::OnDrawZoomout()
{
// TODO: Add your command handler code here
//SetScale(m_Scale * 2.0f);
//SetScale(GetScale() * 2.0f);
}
void CMyView::OnDrawZoompan()
{
// TODO: Add your command handler code here
SendMessage(MYWM_USER_LOST_MOUSERIGHT);
m_bHaveMouseRight = TRUE;
m_LookMode = MM_ZOOMPAN;
//m_CURRENTCURSOR = IDC_ZOOMPANCUR;
m_hCursor = AfxGetApp()->LoadCursor(IDC_ZOOMPANCUR);
}
void CMyView::OnZoomFullextent()
{
//fit to screen
/*
CRect mapRect = m_MapExtent;
CRect clientRect(0,0,0,0);
GetClientRect(clientRect);
CSize size;
CSize sizeSb;
GetTrueClientSize(size, sizeSb);
clientRect.right += sizeSb.cx;
clientRect.bottom += sizeSb.cy;
float scale;
if((float)mapRect.Height() / (float)clientRect.Height() >
(float)mapRect.Width() / (float)clientRect.Width())
{
scale = (float)mapRect.Height() / (float)clientRect.Height();
}
else
{
scale = (float)mapRect.Width() / (float)clientRect.Width();
}
CPoint center;
center.x = (int)(mapRect.left + mapRect.Width() / 2.0);
center.y = (int)(mapRect.top + mapRect.Height() / 2.0);
PointZoom(center,scale);
*/
}
void CMyView::OnZoomNormal()
{
//1:1显示 WM_COMMAND
// long scale;
// double precision;
// ((CGeoDoc*)GetDocument())->GetCurrentWorkspacePrecision(scale, precision);
// if(scale != m_currentTrueScale)
// SetScale((float)scale);
}
void CMyView::MyInvalidate()
{
m_bNeedUpdate = TRUE;
Invalidate();
//m_bNeedUpdate = FALSE;
}
void CMyView::MyInvalidateRect(CRect& rect)
{
m_bNeedUpdate = TRUE;
InvalidateRect(rect);
//m_bNeedUpdate = FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -