Control being created with a valid DC but no window until a refresh is made
-
Hi all, I've got an ATL ActiveX control which only starts correctly the second time it's loaded. The first time it's loaded the DC in the parameter of the OnDraw method cannot be used to get the window it is supposed to be associated with ie a cal to GetWindowFrom DC fails. When checked in spy++ it is clear that this is no error, there is no window being created with the control. Does anyone have an idea why this might be the case and how to resolve it? I'm using XP SP2 VS2005 ATL 8.0 Thanks loads for any help :)
Cheers Tom Philosophy: The art of never getting beyond the concept of life. Religion: Morality taking credit for the work of luck.
-
Hi all, I've got an ATL ActiveX control which only starts correctly the second time it's loaded. The first time it's loaded the DC in the parameter of the OnDraw method cannot be used to get the window it is supposed to be associated with ie a cal to GetWindowFrom DC fails. When checked in spy++ it is clear that this is no error, there is no window being created with the control. Does anyone have an idea why this might be the case and how to resolve it? I'm using XP SP2 VS2005 ATL 8.0 Thanks loads for any help :)
Cheers Tom Philosophy: The art of never getting beyond the concept of life. Religion: Morality taking credit for the work of luck.
Added the following code and fixed the problem:
// this is derived from CComControl
STDMETHOD(SetClientSite)(IOleClientSite *pClientSite)
{
if (pClientSite)
{
RECT rc = {0,0,0,0};
// Don't have access to the container's window so just use the
// desktop. Window will be resized correctly during in-place
// activation.
HWND hWnd = CreateControlWindow(::GetDesktopWindow(), rc);
_ASSERT (hWnd);
}
return IOleObjectImpl::SetClientSite (pClientSite);
}HRESULT InPlaceActivate(LONG iVerb, const RECT\* prcPosRect) { // Get the container's window. \_ASSERT (m\_spClientSite); LPOLEINPLACESITE pInPlaceSite = NULL; HRESULT hr = m\_spClientSite->QueryInterface(IID\_IOleInPlaceSite, (void \*\*)&pInPlaceSite); \_ASSERT (SUCCEEDED (hr) && pInPlaceSite); HWND hParent = NULL; hr = pInPlaceSite->GetWindow (&hParent); \_ASSERT (SUCCEEDED (hr) && hParent); pInPlaceSite->Release (); // Set container window as our parent window SetParent (hParent); return CComControlBase::InPlaceActivate(iVerb, prcPosRect); }
Cheers Tom Philosophy: The art of never getting beyond the concept of life. Religion: Morality taking credit for the work of luck.