📄 zoomout.cpp
字号:
#include "StdAfx.h"
#include ".\zoomout.h"
//////////////////////////////////////////////////////////////////////////
//CZoomout
STDMETHODIMP CZoomout::OnMouseDown(LONG Button, LONG Shift, LONG X, LONG Y)
{
if (MouseDown(X,Y))
{
GetFocusMapActiveView(&m_cpActiveView);
ToFocusMapPoint(X,Y, &m_cpStartPoint);
}
return S_OK;
}
STDMETHODIMP CZoomout::OnMouseMove(LONG Button, LONG Shift, LONG X, LONG Y)
{
if (CMapToolBase::IsMouseDown() && (m_cpStartPoint!=0))
{
if (m_cpEnvelopeFeedback==0)
{
// Start the feedback if its not previously started
m_cpEnvelopeFeedback.CreateInstance(CLSID_NewEnvelopeFeedback);
IScreenDisplayPtr cpScreenDisplay;
m_cpActiveView->get_ScreenDisplay(&cpScreenDisplay);
m_cpEnvelopeFeedback->putref_Display(cpScreenDisplay);
m_cpEnvelopeFeedback->Start(m_cpStartPoint);
}
// Update the feedback to the new point
IPointPtr cpPoint;
ToFocusMapPoint(X,Y, &cpPoint);
m_cpEnvelopeFeedback->MoveTo(cpPoint);
}
return S_OK;
}
STDMETHODIMP CZoomout::OnMouseUp(LONG Button, LONG Shift, LONG X, LONG Y)
{
if (CMapToolBase::IsMouseDown() && (m_cpStartPoint!=0))
{
IEnvelopePtr cpEnvelope;
if (m_cpEnvelopeFeedback == 0)
{
// It was just a click, so zoomout by a fixed amount
m_cpActiveView->get_Extent(&cpEnvelope);
cpEnvelope->Expand( 2, 2, VARIANT_TRUE);
cpEnvelope->CenterAt(m_cpStartPoint);
}
else
{
m_cpEnvelopeFeedback->Stop(&cpEnvelope);
DOUBLE efWidth,efHeight, efXMin, efYMin;
cpEnvelope->get_Width(&efWidth);
cpEnvelope->get_Height(&efHeight);
cpEnvelope->get_XMin(&efXMin);
cpEnvelope->get_YMin(&efYMin);
if (efWidth!=0 && efHeight!=0)
{
DOUBLE avWidth, avHeight, avXMin, avYMin;
IEnvelopePtr cpAvEnvelope;
m_cpActiveView->get_Extent(&cpAvEnvelope);
cpAvEnvelope->get_Width(&avWidth);
cpAvEnvelope->get_Height(&avHeight);
cpAvEnvelope->get_XMin(&avXMin);
cpAvEnvelope->get_YMin(&avYMin);
// The plan is to transform the active view extent into the tracked extent
// and thus expand the new active view
DOUBLE newWidth = avWidth * (avWidth / efWidth);
DOUBLE newHeight = avHeight * (avHeight / efHeight);
DOUBLE newXMin = avXMin - ((efXMin - avXMin) * (avWidth / efWidth));
DOUBLE newYMin = avYMin - ((efYMin - avYMin) * (avHeight / efHeight));
cpEnvelope->PutCoords(newXMin, newYMin, newXMin + newWidth, newYMin + newHeight);
}
else
{
cpEnvelope = 0;
}
}
if (cpEnvelope!=0)
{
m_cpActiveView->put_Extent(cpEnvelope);
m_cpActiveView->Refresh();
}
}
Reset();
return S_OK;
}
STDMETHODIMP CZoomout::OnKeyDown(LONG keyCode, LONG Shift)
{
if (keyCode == VK_ESCAPE)
Reset();
return S_OK;
}
STDMETHODIMP CZoomout::Refresh(OLE_HANDLE hDC)
{
if (m_cpEnvelopeFeedback!=0)
m_cpEnvelopeFeedback->Refresh(hDC);
return S_OK;
}
void CZoomout::Reset()
{
// clear out temp variables release mouse capture in base class
m_cpActiveView = 0;
m_cpStartPoint = 0;
if (m_cpEnvelopeFeedback)
{
IEnvelopePtr cpEnvelope;
m_cpEnvelopeFeedback->Stop(&cpEnvelope);
}
m_cpEnvelopeFeedback = 0;
CMapToolBase::MouseUp();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -