|
// WtlExt.h : WTL Extensions/Helpers
// Copyright: Jes�s Salas 2002 ( jesuspsalas@hotmail.com )
// License : none, feel free to use it.
/////////////////////////////////////////////////////////////////////////////
#pragma once
template <class T,class Interface>
class CWTLDispEventHelper : public IDispEventImpl<0,T>
{
public:
CComPtr<IUnknown> m_pUnk;
HRESULT EasyAdvise(IUnknown* pUnk)
{
m_pUnk = pUnk;
AtlGetObjectSourceInterface(pUnk,&m_libid, &m_iid, &m_wMajorVerNum, &m_wMinorVerNum);
return DispEventAdvise(pUnk, &m_iid);
}
HRESULT EasyUnadvise()
{
AtlGetObjectSourceInterface(m_pUnk,&m_libid, &m_iid, &m_wMajorVerNum, &m_wMinorVerNum);
return DispEventUnadvise(pUnk, &m_iid);
}
};
template <class T, class Interface>
class CWTLAxControl : public CComPtr<Interface>,
public CWindowImpl<CWTLAxControl,CAxWindow>,
public CWTLDispEventHelper<T,Interface>
{
public:
BEGIN_MSG_MAP(CWTLAxControl)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
END_MSG_MAP()
LRESULT OnCreate( UINT uMsg, WPARAM wParam , LPARAM lParam, BOOL & bHandled )
{
LRESULT lRet;
// We must call DefWindowProc before we can attach to the control.
lRet = DefWindowProc( uMsg, wParam,lParam );
// Get the Pointer to the control with Events (true)
AttachControl(true);
return lRet;
}
HRESULT AttachControl( BOOL bWithEvents = false )
{
HRESULT hr = S_OK;
CComPtr<IUnknown> spUnk;
// Get the IUnknown interface of control
hr |= AtlAxGetControl( m_hWnd, &spUnk);
if (SUCCEEDED(hr))
// Query our interface
hr |= spUnk->QueryInterface( __uuidof(Interface), (void**) (CComPtr<Interface>*)this);
//if ( bWithEvents && ! FAILED(hr) )
// Start events
hr|= EasyAdvise( spUnk );
return hr;
};
};
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.