I have been trying to create an ActiveX control that acts like a View
control (I guess more like a FormView is closer.) Anyway, I can create this
control dynamically without any problem. It is sized to fill the client area
of an ActiveX control and then a dialog resource template is passed into a
member function of the View control. The member function parses the template
and creates each of the controls on its client.
I call the following to create the control:
pNewWnd = new CWnd;
pNewWnd->CreateControl( clsid, NULL, WS_VISIBLE | WS_TABSTOP | WS_CHILD,
rect, this, nID, NULL, NULL, NULL );
This is the exact same procedure I use to create the View control on the mdi
window.
I end up getting an assertion and followed the path outlined below. I have
only included the lines that make the calls.
BOOL CWnd::CreateControl( REFCLSID clsid, LPCTSTR lpszWindowName,
DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID,
CFile* pPersist, BOOL bStorage, BSTR bstrLicKey )
return( CreateControl( clsid, lpszWindowName, dwStyle, &pt, &size,
pParentWnd, nID, pPersist, bStorage, bstrLicKey ) );
BOOL CWnd::CreateControl(REFCLSID clsid, LPCTSTR lpszWindowName, DWORD
dwStyle,
const POINT* ppt, const SIZE* psize, CWnd* pParentWnd, UINT nID,
CFile* pPersist, BOOL bStorage, BSTR bstrLicKey)
return pParentWnd->m_pCtrlCont->CreateControl(this, clsid, lpszWindowName,
dwStyle, ppt, psize, nID, pPersist, bStorage, bstrLicKey);
BOOL CWnd::CreateControl(REFCLSID clsid, LPCTSTR lpszWindowName, DWORD
dwStyle,
const POINT* ppt, const SIZE* psize, CWnd* pParentWnd, UINT nID,
CFile* pPersist, BOOL bStorage, BSTR bstrLicKey)
return pParentWnd->m_pCtrlCont->CreateControl(this, clsid, lpszWindowName,
dwStyle, ppt, psize, nID, pPersist, bStorage, bstrLicKey);
BOOL COleControlContainer::CreateControl(CWnd* pWndCtrl, REFCLSID clsid,
LPCTSTR lpszWindowName, DWORD dwStyle, const POINT* ppt, const SIZE* psize,
UINT nID, CFile* pPersist, BOOL bStorage, BSTR bstrLicKey,
COleControlSite** ppNewSite)
BOOL bCreated = SUCCEEDED( pSite->CreateControl(pWndCtrl, clsid,
lpszWindowName, dwStyle, ppt, psize, nID, pPersist, bStorage,
bstrLicKey ) );
HRESULT COleControlSite::CreateControl(CWnd* pWndCtrl, REFCLSID clsid,
LPCTSTR lpszWindowName, DWORD dwStyle, const POINT* ppt, const SIZE* psize,
UINT nID, CFile* pPersist, BOOL bStorage, BSTR bstrLicKey)
if (SUCCEEDED(hr = DoVerb(OLEIVERB_INPLACEACTIVATE)) &&
SUCCEEDED(hr = DoVerb(OLEIVERB_HIDE)))
(OLEIVERB_INPLACEACTIVATE)
HRESULT COleControlSite::DoVerb(LONG nVerb, LPMSG lpMsg)
return m_pObject->DoVerb(nVerb, lpMsg, &m_xOleClientSite, 0,
m_pCtrlCont->m_pWnd->m_hWnd, m_rect);
STDMETHODIMP COleControl::XOleObject::DoVerb(LONG iVerb, LPMSG lpmsg,
LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent, LPCRECT
lprcPosRect)
return pThis->OnActivateInPlace((iVerb != OLEIVERB_INPLACEACTIVATE),
lpmsg);
HRESULT COleControl::OnActivateInPlace(BOOL bUIActivate, LPMSG pMsg)
SendAdvise(OBJECTCODE_SHOWOBJECT);
void COleControl::SendAdvise(UINT uCode)
m_pClientSite->ShowObject();
STDMETHODIMP COleControlSite::XOleClientSite::ShowObject()
pThis->AttachWindow();
void COleControlSite::AttachWindow()
// This call appears to obtain an already exisitng permanent window handle!
if (SUCCEEDED(m_pInPlaceObject->GetWindow(&hWnd)))
.
.
.
ASSERT(m_pWndCtrl->m_pCtrlSite == NULL || m_pWndCtrl->m_pCtrlSite == this);
BOOL CWnd::Attach(HWND hWndNew)
ASSERT(FromHandlePermanent(hWndNew) == NULL);
The ASSERT is what chokes. I have noticed that the line:
if (SUCCEEDED(m_pInPlaceObject->GetWindow(&hWnd)))
obtains a window handle for a permanent window thus causing the ASSERT to
fail.
Why is it getting a window handle already? I realize that it shouldn't as
this is what is supposed to attach the newly created permanent handle with
the pNewWnd I initially created, but it appears somewhere along the line it
has already been attached! Could this be fixed with a flag setting
somewhere?
A few more things...
I created the View control as well as the controls being merged in using the
MFC ActiveX Wizard.
I have also put a call to EnableSimpleFrame() in the constructor of the
View class.
Any help would be greatly appreciated as I have already been wrestling with
this problem for a couple of months and haven't found any solutions in the
books I have or the MSDN CDs or on this board so far!
Stephan A. Puga
stepha...@hansen.com
Dan
Stephan A. Puga wrote in message ...
And by the way, thanks for helping. This just seems like I am missing
something simple and it should be easy to fix, but it is amazing how people
ignore you in a group full of knowledgeable people!
Stephan
Dan O'Brien wrote in message ...