问题1:m_spClientSite是在CComControlBase::IOleObject_SetClientSite中初始化
m_spInPlaceSite 在什么时候初始化
问题2:GIF98控件不传窗口进去,怎么让他的m_HWND 不为空

解决方案 »

  1.   

    1)ATL源码inline HRESULT CComControlBase::InPlaceActivate(LONG iVerb, const RECT* /*prcPosRect*/)
    {
    HRESULT hr; if (m_spClientSite == NULL)
    return S_OK; CComPtr<IOleInPlaceObject> pIPO;
    ControlQueryInterface(__uuidof(IOleInPlaceObject), (void**)&pIPO);
    ATLASSERT(pIPO != NULL); if (!m_bNegotiatedWnd)
    {
    if (!m_bWindowOnly)
    // Try for windowless site
    hr = m_spClientSite->QueryInterface(__uuidof(IOleInPlaceSiteWindowless), (void **)&m_spInPlaceSite); if (m_spInPlaceSite)
    {
    m_bInPlaceSiteEx = TRUE;
    // CanWindowlessActivate returns S_OK or S_FALSE
    if ( m_spInPlaceSite->CanWindowlessActivate() == S_OK )
    {
    m_bWndLess = TRUE;
    m_bWasOnceWindowless = TRUE;
    }
    else
    {
    m_bWndLess = FALSE;
    }
    }
    else
    {
    m_spClientSite->QueryInterface(__uuidof(IOleInPlaceSiteEx), (void **)&m_spInPlaceSite);
    if (m_spInPlaceSite)
    m_bInPlaceSiteEx = TRUE;
    else
    hr = m_spClientSite->QueryInterface(__uuidof(IOleInPlaceSite), (void **)&m_spInPlaceSite);
    }
    } ATLASSUME(m_spInPlaceSite);
    if (!m_spInPlaceSite)
    return E_FAIL; m_bNegotiatedWnd = TRUE; if (!m_bInPlaceActive)
    { BOOL bNoRedraw = FALSE;
    if (m_bWndLess)
    m_spInPlaceSite->OnInPlaceActivateEx(&bNoRedraw, ACTIVATE_WINDOWLESS);
    else
    {
    if (m_bInPlaceSiteEx)
    m_spInPlaceSite->OnInPlaceActivateEx(&bNoRedraw, 0);
    else
    {
    hr = m_spInPlaceSite->CanInPlaceActivate();
    // CanInPlaceActivate returns S_FALSE or S_OK
    if (FAILED(hr))
    return hr;
    if ( hr != S_OK )
    {
       // CanInPlaceActivate returned S_FALSE.
       return( E_FAIL );
    }
    m_spInPlaceSite->OnInPlaceActivate();
    }
    }
    } m_bInPlaceActive = TRUE; // get location in the parent window,
    // as well as some information about the parent
    //
    OLEINPLACEFRAMEINFO frameInfo;
    RECT rcPos, rcClip;
    CComPtr<IOleInPlaceFrame> spInPlaceFrame;
    CComPtr<IOleInPlaceUIWindow> spInPlaceUIWindow;
    frameInfo.cb = sizeof(OLEINPLACEFRAMEINFO);
    HWND hwndParent;
    if (m_spInPlaceSite->GetWindow(&hwndParent) == S_OK)
    {
    m_spInPlaceSite->GetWindowContext(&spInPlaceFrame,
    &spInPlaceUIWindow, &rcPos, &rcClip, &frameInfo); if (!m_bWndLess)
    {
    if (m_hWndCD)
    ShowWindow(m_hWndCD, SW_SHOW);
    else
    {
    HWND h = CreateControlWindow(hwndParent, rcPos);
    ATLASSERT(h != NULL); // will assert if creation failed
    ATLASSERT(h == m_hWndCD);
    if(h == NULL)
    return E_FAIL;
    }
    } pIPO->SetObjectRects(&rcPos, &rcClip);
    } CComPtr<IOleInPlaceActiveObject> spActiveObject;
    ControlQueryInterface(__uuidof(IOleInPlaceActiveObject), (void**)&spActiveObject); // Gone active by now, take care of UIACTIVATE
    if (DoesVerbUIActivate(iVerb))
    {
    if (!m_bUIActive)
    {
    m_bUIActive = TRUE;
    hr = m_spInPlaceSite->OnUIActivate();
    if (FAILED(hr))
    {
    m_bUIActive = FALSE;
    return hr;
    } SetControlFocus(TRUE);
    // set ourselves up in the host.
    //
    if (spActiveObject)
    {
    if (spInPlaceFrame)
    spInPlaceFrame->SetActiveObject(spActiveObject, NULL);
    if (spInPlaceUIWindow)
    spInPlaceUIWindow->SetActiveObject(spActiveObject, NULL);
    } if (spInPlaceFrame)
    spInPlaceFrame->SetBorderSpace(NULL);
    if (spInPlaceUIWindow)
    spInPlaceUIWindow->SetBorderSpace(NULL);
    }
    } m_spClientSite->ShowObject(); return S_OK;
    }
    2)GIF98控件不熟悉
      

  2.   

    楼上那位大哥:if (m_spClientSite == NULL)
            return S_OK;
    那不是m_spClientSite 没能初始化了,我现在的控件就是为NULL,请深一步,谢谢
      

  3.   


    m_spClientSite在CComControlBase::IOleObject_SetClientSite中初始化当然是调用着调用SetClientSite来初始化啦