
I'm trying to add a windowless active X control to a CWnd dialog.
The problem is, if I attach my control during OnInitDialog, the control is later detached via COleControlSite:
etachWindow, and is therefore not shown. I can get it to work by creating my control later, when the parent control is getting a WM_SIZE message for the second time...but this is really hacky and I don't understand it.
So...the below code works, but I'd rather not have the hack / understand what's going on
Code:
CParentControl::CParentControl()
{
m_pChild = NULL;
}
void CParentControl::OnInitDialog()
{
// This is successful, but Windows detaches the control soon after
CreateChild();
}
LRESULT CParentControl::OnSize (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (!m_pChild)
{
if (lParam == 0)
{
// This is successful, but Windows detaches the control soon after
CreateChild();
}
else
{
// This works, and creates a permanent control! But why?
CreateChild();
}
}
}
void CreateChild ()
{
CWnd * me = CWnd::FromHandle(m_hWnd);
// This always returns a success code...
BOOL ret = m_pChild->CreateControl( clsid, NULL, WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, CRect(10,10,300,300), me, 0);
}
