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

📄 mapcommandbase.cpp

📁 在vc环境下
💻 CPP
字号:
// MapCommandBase.cpp: implementation of the CMapCommandBase class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "HookHelper.h"
#include "MapCommandBase.h"
#include "resource.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMapCommandBase::CMapCommandBase(UINT bitmapID,
								 UINT caption,
								 UINT category,
								 UINT tooltip,
								 UINT message,
								 UINT helpfile,
								 LONG helpID)
{

	if (bitmapID)
		m_hBitmap = (HBITMAP) ::LoadImage(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(bitmapID),
		IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);

	if (caption)
		m_bstrCaption.LoadString(caption);

	if (category)
		m_bstrCategory.LoadString(category);

	if (caption)
	{
		// Make name from caption and category
		m_bstrName = m_bstrCaption;
		m_bstrName.Append("_");
		m_bstrName.Append(m_bstrCategory);
	}

	if (tooltip)
		m_bstrTooltip.LoadString(tooltip);
	else if (caption)
		m_bstrTooltip = m_bstrCaption;

	if (message)
		m_bstrMessage.LoadString(message);
	else if (caption)
		m_bstrMessage = m_bstrCaption;

	if (helpfile)
		m_bstrHelpfile.LoadString(helpfile);
}

CMapCommandBase::~CMapCommandBase()
{

	if (m_hBitmap)
		::DeleteObject(m_hBitmap);
	m_hBitmap = 0;

}


STDMETHODIMP CMapCommandBase::get_Caption(BSTR * Caption)
{
	*Caption = m_bstrCaption.Copy();

	return S_OK;
}

STDMETHODIMP CMapCommandBase::get_Name(BSTR * Name)
{
	*Name = m_bstrName.Copy();

	return S_OK;
}

STDMETHODIMP CMapCommandBase::get_Tooltip(BSTR * Tooltip)
{
	*Tooltip = m_bstrTooltip.Copy();

	return S_OK;
}

STDMETHODIMP CMapCommandBase::get_Message(BSTR * Message)
{
	*Message = m_bstrMessage.Copy();

	return S_OK;
}



STDMETHODIMP CMapCommandBase::get_Enabled(VARIANT_BOOL * Enabled)
{
	if (Enabled == NULL)
		return E_POINTER;

	// Must have focus map to be enabled
	IActiveViewPtr cpActiveView;
	GetFocusMapActiveView(&cpActiveView);

	*Enabled = (cpActiveView == 0) ? VARIANT_FALSE : VARIANT_TRUE;

	return S_OK;
}

STDMETHODIMP CMapCommandBase::get_Checked(VARIANT_BOOL * Checked)
{
	if (Checked == NULL)
		return E_POINTER;

	*Checked = VARIANT_FALSE;

	return S_OK;
}


STDMETHODIMP CMapCommandBase::get_HelpFile(BSTR * HelpFile)
{
	if (HelpFile == NULL)
		return E_POINTER;

	return E_NOTIMPL;
}
STDMETHODIMP CMapCommandBase::get_HelpContextID(LONG * helpID)
{
	if (helpID == NULL)
		return E_POINTER;

	return E_NOTIMPL;
}

STDMETHODIMP CMapCommandBase::get_Bitmap(OLE_HANDLE * Bitmap)
{
	if (Bitmap == NULL)
		return E_POINTER;

	*Bitmap = (OLE_HANDLE) m_hBitmap;

	return S_OK;
}

STDMETHODIMP CMapCommandBase::get_Category(BSTR * categoryName)
{
	if (categoryName == NULL)
		return E_POINTER;

	*categoryName = m_bstrCategory.Copy();

	return E_NOTIMPL;
}

STDMETHODIMP CMapCommandBase::OnCreate(IDispatch * hook)
{
	HRESULT hr = m_hookHelper.putref_Hook(hook);
	return hr;
}


STDMETHODIMP CMapCommandBase::OnClick()
{
	return S_OK;
}



/////////////////////////////
//Helper Function
//Return FocusMap's ActiveView
HRESULT CMapCommandBase::GetFocusMapActiveView(IActiveView** ppActiveView)
{
	if (ppActiveView == 0)
		return E_POINTER;

	IActiveViewPtr cpActiveView;
	IMapPtr cpMap;
	m_hookHelper.get_FocusMap(&cpMap);
	if (cpMap)
		cpActiveView = cpMap;

	*ppActiveView = cpActiveView.Detach();

	return S_OK;
}

//Return FocusMap's ScreenDisplay
HRESULT CMapCommandBase::GetFocusMapScreenDisplay(IScreenDisplay** ppScreenDisplay)
{
	if (ppScreenDisplay==0)
		return E_POINTER;

	IActiveViewPtr cpActiveView;
	GetFocusMapActiveView(&cpActiveView);
	IScreenDisplayPtr cpScreenDisplay;

	if (cpActiveView)
		cpActiveView->get_ScreenDisplay(&cpScreenDisplay);

	*ppScreenDisplay = cpScreenDisplay.Detach();

	return S_OK;
}


HRESULT CMapCommandBase::ToFocusMapPoint(LONG X, LONG Y, IPoint** ppPoint)
{
	IActiveViewPtr cpActiveView;
	GetFocusMapActiveView(&cpActiveView);

	if (cpActiveView == 0)
		return E_FAIL;

	HRESULT hr = S_OK;

	IScreenDisplayPtr cpScreenDisplay;
	IDisplayTransformationPtr cpDisplayTrans;

	hr = cpActiveView->get_ScreenDisplay(&cpScreenDisplay);
	if (cpScreenDisplay)
		hr = cpScreenDisplay->get_DisplayTransformation(&cpDisplayTrans);

	if (cpDisplayTrans)
		hr = cpDisplayTrans->ToMapPoint(X, Y, ppPoint);

	return hr;
}

⌨️ 快捷键说明

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