Win32编程点滴 - 简单ActiveX控件的使用
2010-01-10 09:37:18 来源:WEB开发网CControlContainer类的实现非常简单,基本上IOleClientSite和IOleInPlaceSite接口大部分的方法 都只要简单的返回S_OK或E_NOTIMPLE即可。唯一需要实现的是IUnknown的方法,还有IOleWindow接口 (IOleInPlaceSite继承于IOleWindow)的GetWindow(返回父窗口的句柄)。代码如下:
class CControlContainer:public IOleClientSite,public IOleInPlaceSite
{
HWND m_hWnd;
ULONG m_refCnt;
public:
CControlContainer (HWND hWnd)
{
m_hWnd = hWnd;
m_refCnt = 1;
}
~CControlContainer()
{
}
.... IUnknown的实现
//IOleControlSite
STDMETHOD(SaveObject())
{
return E_NOTIMPL;
}
STDMETHOD(GetMoniker(DWORD,DWORD,IMoniker**))
{
return E_NOTIMPL;
}
STDMETHOD(GetContainer(IOleContainer **ppContainer))
{
return E_NOINTERFACE;
}
STDMETHOD(ShowObject())
{
return S_OK;
}
STDMETHOD(OnShowWindow(BOOL bShow))
{
return S_OK;
}
STDMETHOD(RequestNewObjectLayout())
{
return E_NOTIMPL;
}
//IOleWindow
STDMETHOD(GetWindow(HWND * pHwnd))
{
*pHwnd = m_hWnd;
return S_OK;
}
STDMETHOD (ContextSensitiveHelp(BOOL bEnterMode))
{
return S_OK;
}
//IOleInPlaceSite
STDMETHOD(CanInPlaceActivate())
{
return S_OK;
}
STDMETHOD(OnInPlaceActivate())
{
return S_OK;
}
STDMETHOD(OnUIActivate())
{
return S_OK;
}
STDMETHOD(GetWindowContext(/* [out] */ IOleInPlaceFrame **ppFrame,
/* [out] */ IOleInPlaceUIWindow **ppDoc,
/* [out] */ LPRECT lprcPosRect,
/* [out] */ LPRECT lprcClipRect,
/* [out][in] */ LPOLEINPLACEFRAMEINFO lpFrameInfo))
{
return E_NOTIMPL;
}
STDMETHOD(Scroll(SIZE scrollSize))
{
return S_OK;
}
STDMETHOD (OnUIDeactivate(BOOL bUndoable))
{
return S_OK;
}
STDMETHOD(OnInPlaceDeactivate())
{
return S_OK;
}
STDMETHOD(DiscardUndoState())
{
return S_OK;
}
STDMETHOD(DeactivateAndUndo())
{
return S_OK;
}
STDMETHOD(OnPosRectChange(LPCRECT lprcPosRect))
{
return S_OK;
}
};
更多精彩
赞助商链接