分类: C/C++
2008-05-31 11:40:38
public CComObjectRootEx
public CComCoClass
public IZoomIn,
public ICommand,
public CProxyISceneGraphEvents< CZoomIn >,
public IConnectionPointContainerImpl
{
public:
CZoomIn()
{
m_hBitmap = ::LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_ZOOMIN));
}
~CZoomIn()
{
DeleteObject(m_hBitmap);
}
IHookHelperPtr m_ipHookHelper;
ISceneHookHelperPtr m_ipSceneHookHelper;
DECLARE_REGISTRY_RESOURCEID(IDR_ZOOMIN)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CZoomIn)
COM_INTERFACE_ENTRY(IZoomIn)
COM_INTERFACE_ENTRY(ICommand)
COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
END_COM_MAP()
// IZoomIn private:
HBITMAP m_hBitmap;
public:
// ICommand
STDMETHOD(get_Enabled)(VARIANT_BOOL * Enabled);
STDMETHOD(get_Checked)(VARIANT_BOOL * Checked);
STDMETHOD(get_Name)(BSTR * Name);
STDMETHOD(get_Caption)(BSTR * Caption);
STDMETHOD(get_Tooltip)(BSTR * Tooltip);
STDMETHOD(get_Message)(BSTR * Message);
STDMETHOD(get_HelpFile)(BSTR * HelpFile);
STDMETHOD(get_HelpContextID)(LONG * helpID);
STDMETHOD(get_Bitmap)(OLE_HANDLE * Bitmap);
STDMETHOD(get_Category)(BSTR * categoryName);
STDMETHOD(OnCreate)(IDispatch * hook);
STDMETHOD(OnClick)();
public :
BEGIN_CONNECTION_POINT_MAP(CZoomIn)
CONNECTION_POINT_ENTRY(IID_ISceneGraphEvents)
END_CONNECTION_POINT_MAP()
};
#endif //__ZOOMIN_H_
// ZoomIn.cpp : Implementation of CZoomIn
#include \"stdafx.h\"
#include \"Walkthrough1Cpp.h\"
#include \"ZoomIn.h\"
/////////////////////////////////////////////////////////////////////////////
// CZoomIn
STDMETHODIMP CZoomIn::get_Enabled(VARIANT_BOOL * Enabled)
{
if (Enabled == NULL)
return E_POINTER;
*Enabled = VARIANT_TRUE; // Enable the tool always
return S_OK;
}
STDMETHODIMP CZoomIn::get_Checked(VARIANT_BOOL * Checked)
{
if (Checked == NULL)
return E_POINTER;
return E_NOTIMPL;
}
STDMETHODIMP CZoomIn::get_Name(BSTR * Name)
{
if (Name == NULL) [Page]
return E_POINTER;
*Name = ::SysAllocString(L\"ZoomIn x 0.5 Cpp\");
return S_OK;
}
STDMETHODIMP CZoomIn::get_Caption(BSTR * Caption)
{
if (Caption == NULL)
return E_POINTER;
*Caption = ::SysAllocString(L\"ZoomIn x 0.5 Cpp\");
return S_OK;
}
STDMETHODIMP CZoomIn::get_Tooltip(BSTR * Tooltip)
{
if (Tooltip == NULL)
return E_POINTER;
return E_NOTIMPL;
}
STDMETHODIMP CZoomIn::get_Message(BSTR * Message)
{
if (Message == NULL)
return E_POINTER;
return E_NOTIMPL;
}
STDMETHODIMP CZoomIn::get_HelpFile(BSTR * HelpFile)
{
if (HelpFile == NULL)
return E_POINTER;
return E_NOTIMPL;
}
STDMETHODIMP CZoomIn::get_HelpContextID(LONG * helpID)
{
if (helpID == NULL)
return E_POINTER;
return E_NOTIMPL;
}
STDMETHODIMP CZoomIn::get_Bitmap(OLE_HANDLE * Bitmap)
{
if (Bitmap == NULL)
return E_POINTER;
*Bitmap = (OLE_HANDLE) m_hBitmap;
return S_OK;
}
STDMETHODIMP CZoomIn::get_Category(BSTR * categoryName)
{
if (categoryName == NULL)
return E_POINTER;
*categoryName = ::SysAllocString(L\"Developer Samples\");
return S_OK;
}
STDMETHODIMP CZoomIn::OnCreate(IDispatch * hook)
{
m_ipSceneHookHelper.CreateInstance(CLSID_SceneHookHelper);
HRESULT hr = m_ipSceneHookHelper->putref_Hook(hook);
return hr;
}
STDMETHODIMP CZoomIn::OnClick()
{
// HRESULT checking omitted for clarity
IScenePtr ipScene;
m_ipSceneHookHelper->get_Scene(&ipScene);
ISceneGraphPtr ipSceneGraph;
ipScene->get_SceneGraph(&ipSceneGraph);
ISceneViewer * pViewer;
ipSceneGraph->get_ActiveViewer(&pViewer); [Page]
Fire_BeforeDraw(pViewer, NULL);
ipSceneGraph->RefreshViewers();
Fire_AfterDraw(pViewer);
return S_OK;
} // Walkthrough1Cpp.idl : IDL source for Walkthrough1Cpp.dll
//
// This file will be processed by the MIDL tool to
// produce the type library (Walkthrough1Cpp.tlb) and marshalling code.
import \"oaidl.idl\";
import \"ocidl.idl\";
[
object,
uuid(5CA669DE-0DFE-4C49-8546-B8AE24A629D5),
helpstring(\"IZoomIn Interface\"),
pointer_default(unique)
]
interface IZoomIn : IUnknown
{
};
[
uuid(5C0841D7-80E7-4CDB-AFCD-5D77B23B879E),
version(1.0),
helpstring(\"Walkthrough1Cpp 1.0 Type Library\")
]
library WALKTHROUGH1CPPLib
{
importlib(\"stdole32.tlb\");
importlib(\"stdole2.tlb\");
importlib(\"e:\\Program Files\\ArcGIS\\com\\esriSystemUI.olb\");
[
uuid(C9265E95-7317-4CB2-9ACC-E3EA5C9CA550),
helpstring(\"ZoomIn Class\")
]
coclass ZoomIn
{
[default] interface IUnknown;
interface IZoomIn;
interface ICommand;
// [default] interface IZoomIn;
};
};
//esri3DAnalystCP.h
#ifndef _ESRI3DANALYSTCP_H_
#define _ESRI3DANALYSTCP_H_
#import \"E:\\Program Files\\ArcGIS\\com\\esri3DAnalyst.olb\" raw_interfaces_only, raw_native_types,
no_namespace, named_guids //\"Import typelib\"
template
class CProxyISceneGraphEvents : public IConnectionPointImpl
{
//Warning this class may be recreated by the wizard.
public:
HRESULT Fire_ActiveViewerChanged(ISceneViewer * pViewer)
{
HRESULT ret;
T* pT = static_cast
int nConnectionIndex;
int nConnections = m_vec.GetSize();
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
{
pT->Lock();
CComPtr
pT->Unlock();
ISceneGraphEvents* pISceneGraphEvents = reinterpret_cast
(sp.p);
if (pISceneGraphEvents != NULL)
ret = pISceneGraphEvents->ActiveViewerChanged(pViewer);
} return ret;
}
HRESULT Fire_ViewerAdded(ISceneViewer * pViewer)
{
HRESULT ret;
T* pT = static_cast
int nConnectionIndex;
int nConnections = m_vec.GetSize();
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
{
pT->Lock();
CComPtr
pT->Unlock();
ISceneGraphEvents* pISceneGraphEvents = reinterpret_cast
(sp.p);
if (pISceneGraphEvents != NULL)
ret = pISceneGraphEvents->ViewerAdded(pViewer);
} return ret;
} HRESULT Fire_ViewerRemoved(ISceneViewer * pViewer)
{
HRESULT ret;
T* pT = static_cast
int nConnectionIndex;
int nConnections = m_vec.GetSize();
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
{
pT->Lock();
CComPtr
pT->Unlock();
ISceneGraphEvents* pISceneGraphEvents = reinterpret_cast
(sp.p);
if (pISceneGraphEvents != NULL)
ret = pISceneGraphEvents->ViewerRemoved(pViewer);
} return ret;
}
HRESULT Fire_InteractionStopped()
{
HRESULT ret;
T* pT = static_cast
int nConnectionIndex;
int nConnections = m_vec.GetSize();
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++) [Page]
{
pT->Lock();
CComPtr
pT->Unlock();
ISceneGraphEvents* pISceneGraphEvents = reinterpret_cast
(sp.p);
if (pISceneGraphEvents != NULL)
ret = pISceneGraphEvents->InteractionStopped();
} return ret;
}
HRESULT Fire_RecordingStarted(BSTR Name)
{
HRESULT ret;
T* pT = static_cast
int nConnectionIndex;
int nConnections = m_vec.GetSize();
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
{
pT->Lock();
CComPtr
pT->Unlock();
ISceneGraphEvents* pISceneGraphEvents = reinterpret_cast
(sp.p);
if (pISceneGraphEvents != NULL)
ret = pISceneGraphEvents->RecordingStarted(Name);
} return ret;
}
HRESULT Fire_RecordingStopped()
{
HRESULT ret;
T* pT = static_cast
int nConnectionIndex;
int nConnections = m_vec.GetSize();
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
{
pT->Lock();
CComPtr
pT->Unlock();
ISceneGraphEvents* pISceneGraphEvents = reinterpret_cast
(sp.p);
if (pISceneGraphEvents != NULL)
ret = pISceneGraphEvents->RecordingStopped();
} return ret;
}
HRESULT Fire_BeforeDraw(ISceneViewer * pViewer, VARIANT_BOOL * pbHandled)
{
ISceneGraphPtr ipSceneGraph;
pViewer->get_SceneGraph(&ipSceneGraph); [Page]
IEnvelopePtr pExtent;
ipSceneGraph->get_Extent(&pExtent);
ICameraPtr pCamera;
pViewer->get_Camera(&pCamera);
double Near;
double Far;
double Angle;
double m_aspect;
pCamera->QueryViewingPlatformMBB(pExtent, &Near, &Far, &Angle, &m_aspect);
glEnable(GL_FOG);
glFogf(GL_FOG_MODE, GL_LINEAR);
glFogf(GL_FOG_START, Near);
glFogf(GL_FOG_END, Far);
float red = 0.8;
float green = 0.4;
float blue = 0.4;
GLfloat FogColor[4] = {red, green, blue, 1};
glFogfv(GL_FOG_COLOR, FogColor);
HRESULT ret;
T* pT = static_cast
int nConnectionIndex;
int nConnections = m_vec.GetSize();
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
{
pT->Lock();
CComPtr
pT->Unlock();
ISceneGraphEvents* pISceneGraphEvents = reinterpret_cast
(sp.p);
if (pISceneGraphEvents != NULL)
ret = pISceneGraphEvents->BeforeDraw(pViewer, pbHandled);
} return ret;
}
HRESULT Fire_AfterDraw(ISceneViewer * pViewer)
{
glDisable(GL_FOG);
HRESULT ret;
T* pT = static_cast
int nConnectionIndex;
int nConnections = m_vec.GetSize();
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
{
pT->Lock();
CComPtr
pT->Unlock();
ISceneGraphEvents* pISceneGraphEvents = reinterpret_cast
(sp.p);
if (pISceneGraphEvents != NULL)
ret = pISceneGraphEvents->AfterDraw(pViewer);
} return ret;
}
};
#endif
处理前