Figure 1 GetContainerHwnd
lpOleWnd->Release();
HWND CMSJDragCtrl::GetContainerHWnd()
{
LPOLEWINDOW lpOleWnd;
HWND docWnd = NULL;
HRESULT hRes;
// If the control exists with an hWnd, this call will use its
// IOleInPlaceSite pointer to retrieve the container's IOleWindow.
// From there, IOleWindow can be queried to retrieve the container's
// hWnd.
if (m_pInPlaceSite) // Should always be ok
{
hRes = m_pInPlaceSite->QueryInterface(IID_IOleWindow,
(LPVOID *) &lpOleWnd);
if (SUCCEEDED(hRes))
{
hRes = lpOleWnd->GetWindow(&docWnd);
if (SUCCEEDED(hRes))
{
lpOleWnd->Release();
}
}
}
return docWnd;
}
Figure 2 Setting Up a Link to a Container Window
int CMSJDragCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
HWND hw;
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
// Call our control's added procedure to get its
// container window through its OLE interfaces.
hw = GetContainerHWnd();
// Tell the container to accept dragged files.
::DragAcceptFiles(hw, TRUE);
// Initialize the m_framewnd object with the real frame
// window we just retrieved.
m_framewnd.SubclassWindow(hw);
// Initialize the frame window's pointer back to this
// control object. This allows the framewnd class to
// fire off an event through this control class.
m_framewnd.m_ctrlwnd = this;
return 0;
}