hapyfishrmn
hapyfishrmn

Reputation: 177

Getting ActiveX window handle

I have followed this link to get the window handle of a ActiveX control

Sample Code from microsoft's site

// The following code should return the actual parent window of the ActiveX control.
HWND CMyOleControl::GetActualParent()
{
   HWND hwndParent = 0;

   // Get the window associated with the in-place site object,
   // which is connected to this ActiveX control.
   if (m_pInPlaceSite != NULL)
       m_pInPlaceSite->GetWindow(&hwndParent);

   return hwndParent;     // Return the in-place site window handle.
}

But in my case I keep finding that "m_pInPlaceSite" is always NULL. I'm trying to run this code in my controls FinalConstruct. Is there something else I need to implement for the m_pInPlaceSite to be given a value? Or do I need to Query to get the value.

Thanks

Upvotes: 2

Views: 1550

Answers (1)

Roman Ryltsov
Roman Ryltsov

Reputation: 69672

FinalConstruct is way too early. In FinalConstruct your class is just being created and is not yet initialized. There is no "in place" site, there is no yet site at all.

Your control will be called by its owner, it will be given its site, then activated - only then you will possibly have m_pInPlaceSite available.

Upvotes: 1

Related Questions