📄 maptoolbase.cpp
字号:
// MapToolBase.cpp: implementation of the CMapToolBase class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MapToolBase.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
CMapToolBase::CMapToolBase(
WORD wBitmapID,
UINT caption,
UINT category,
UINT tooltip,
UINT message,
UINT helpfile,
LONG helpID,
UINT cursorID,
UINT cursorMoveID ) :
CMapCommandBase(wBitmapID, caption, category, tooltip, message, helpfile, helpID),
m_hCursor(0),
m_hCursorMove(0),
m_bMouseDown(false)
{
if (cursorID)
m_hCursor = (HCURSOR) ::LoadImage(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(cursorID),
IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE);
if (cursorMoveID)
m_hCursorMove = (HCURSOR) ::LoadImage(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(cursorMoveID),
IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE);
else if (cursorID !=0)
m_hCursorMove = m_hCursor; // if no move cursor supplied use the normal cursor
}
CMapToolBase::~CMapToolBase()
{
if (m_hCursor!=0)
::DestroyCursor(m_hCursor);
if ((m_hCursorMove!=0) && (m_hCursor != m_hCursorMove))
::DestroyCursor(m_hCursorMove);
m_hCursor = 0;
m_hCursorMove = 0;
}
STDMETHODIMP CMapToolBase::get_Cursor(OLE_HANDLE * Cursor)
{
if (Cursor == NULL)
return E_POINTER;
if (m_bMouseDown)
*Cursor = (OLE_HANDLE)m_hCursorMove;
else
*Cursor = (OLE_HANDLE)m_hCursor;
return S_OK;
}
STDMETHODIMP CMapToolBase::OnMouseDown(LONG Button, LONG Shift, LONG X, LONG Y)
{
return S_OK;
}
STDMETHODIMP CMapToolBase::OnMouseMove(LONG Button, LONG Shift, LONG X, LONG Y)
{
return S_OK;
}
STDMETHODIMP CMapToolBase::OnMouseUp(LONG Button, LONG Shift, LONG X, LONG Y)
{
return S_OK;
}
STDMETHODIMP CMapToolBase::OnDblClick()
{
return S_OK;
}
STDMETHODIMP CMapToolBase::OnKeyDown(LONG keyCode, LONG Shift)
{
return S_OK;
}
STDMETHODIMP CMapToolBase::OnKeyUp(LONG keyCode, LONG Shift)
{
return S_OK;
}
STDMETHODIMP CMapToolBase::OnContextMenu(LONG X, LONG Y, VARIANT_BOOL * handled)
{
return S_OK;
}
STDMETHODIMP CMapToolBase::Refresh(OLE_HANDLE hDC)
{
return S_OK;
}
STDMETHODIMP CMapToolBase::Deactivate(VARIANT_BOOL * complete)
{
*complete = VARIANT_TRUE;
return S_OK;
}
///////////////////////////////////////////////////////////////////
//
HRESULT CMapToolBase::SetFocusMap(LONG X, LONG Y)
{
HRESULT hr;
IActiveViewPtr cpActiveView;
m_hookHelper.get_ActiveView(&cpActiveView);
IPageLayoutPtr cpPageLayout(cpActiveView);
if (cpPageLayout != 0 && cpActiveView!=0)
{
IPointPtr cpPoint;
IScreenDisplayPtr cpScreenDisplay;
IDisplayTransformationPtr cpDisplayTrans;
IMapPtr cpHitMap;
hr = cpActiveView->get_ScreenDisplay(&cpScreenDisplay);
if (cpScreenDisplay)
hr = cpScreenDisplay->get_DisplayTransformation(&cpDisplayTrans);
if (cpDisplayTrans)
hr = cpDisplayTrans->ToMapPoint(X, Y, &cpPoint);
if (cpPoint)
hr = cpActiveView->HitTestMap(cpPoint, &cpHitMap);
if (cpHitMap != 0)
{
IMapPtr cpOldMap;
hr = cpActiveView->get_FocusMap(&cpOldMap);
if (cpOldMap != cpHitMap)
{
// Clicked on a differnt map, change the focus map
hr = cpActiveView->putref_FocusMap(cpHitMap);
cpActiveView->PartialRefresh(esriViewGraphics,0,0);
}
}
else
hr = S_FALSE; // Didn't hit a map
}
else
hr = S_OK; // Not a page layout, so focus map does not apply
return hr;
}
bool CMapToolBase::MouseDown(LONG X, LONG Y)
{
m_bMouseDown = false;
// Update focus map to the place thats clicked on
HRESULT hr = SetFocusMap(X, Y);
if (hr == S_FALSE || FAILED(hr))
return false;
m_bMouseDown = true;
HCURSOR hCur;
get_Cursor((OLE_HANDLE*) &hCur);
::SetCursor(hCur);
// Capture all mouse events outside the window while mouse is down
HWND hWnd;
m_hookHelper.get_hWnd(&hWnd);
::SetCapture(hWnd);
return true;
}
void CMapToolBase::MouseUp()
{
m_bMouseDown = false;
HCURSOR hCur;
get_Cursor((OLE_HANDLE*) &hCur);
::SetCursor(hCur);
// Release the capture
HWND hWnd;
m_hookHelper.get_hWnd(&hWnd);
if (::GetCapture() == hWnd)
::ReleaseCapture();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -