MSDN的列子 获得的是Internet Explorer_Server窗口 的父窗口的父窗口的句柄 不是我想要的。
IServiceProvider* pServiceProvider = NULL;
if (SUCCEEDED(pWebBrowser2->QueryInterface(
                    IID_IServiceProvider, 
                    (void**)&pServiceProvider)))
{
    IOleWindow* pWindow = NULL;
    if (SUCCEEDED(pServiceProvider->QueryService(
                    SID_SShellBrowser, 
                    IID_IOleWindow,
                    (void**)&pWindow)))
    {
        HWND hwndBrowser = NULL;
        if (SUCCEEDED(pWindow->GetWindow(&hwndBrowser)))
        {
            // hwndBrowser is the handle of TabWindowClass
        }        pWindow->Release();
    }
 
    pServiceProvider->Release();

通过CDHtmlDialog成员变量m_pBrowserApp->get_HWND()结果失败。
到底该如何做呢?

解决方案 »

  1.   

    EnumChildWindows为什么也找不到呢?EnumChildWindows(this->m_hWnd,EnumChildProc,NULL);
    BOOL CALLBACK EnumChildProc(          HWND hwnd,
    LPARAM lParam
    )
    {
    TCHAR buffer[128];
    GetClassName(hwnd,buffer,sizeof(buffer)/sizeof(TCHAR));
    if(0 == strcmp(buffer,_T("Internet Explorer_Server")))
    {
    g_pWebDlg->m_hWBCWnd = hwnd;
    return FALSE;
    }
    return TRUE;
      

  2.   

    成功了!BOOL CALLBACK EnumChildProc( HWND hwnd,LPARAM lParam)
    {
    TCHAR lpBuf[128];
    GetClassName(hwnd,lpBuf,sizeof(lpBuf)/sizeof(TCHAR));
    if(_tcscmp(lpBuf,_T("Internet Explorer_Server")) == 0)
    {
    *((LONG*)lParam) = (LPARAM)hwnd;
    return FALSE;
    }
    return TRUE;
    }
    IServiceProvider* pServiceProvider = NULL;
    if (SUCCEEDED(pWebBrowser2->QueryInterface(
    IID_IServiceProvider, 
    (void**)&pServiceProvider)))
    {
    IOleWindow* pWindow = NULL;
    if (SUCCEEDED(pServiceProvider->QueryService(
    SID_SShellBrowser, 
    IID_IOleWindow,
    (void**)&pWindow)))
    {
    HWND hwndBrowser = NULL;
    if (SUCCEEDED(pWindow->GetWindow(&hwndBrowser)))
    {
    LONG lParam = 0;
    EnumChildWindows(hwndBrowser,EnumChildProc,(LPARAM)&lParam);
    HWND hwndss = (HWND)lParam; // hwndss就是了
    int a = 0;
    a++;
    // hwndBrowser is the handle of TabWindowClass
    } pWindow->Release();
    } pServiceProvider->Release();
    }
      

  3.   

    楼主 何必去枚举窗口句柄呢
    直接在用CDHtmlDialog的句柄FindWindow就可以了
            HWND m_ieHwnd = ::FindWindowEx(GetSafeHwnd(), 0, "Shell Embedding", NULL);

    if (m_ieHwnd)
    {
    m_ieHwnd = ::FindWindowEx(m_ieHwnd, 0, "Shell DocObject View", NULL);
    if (m_ieHwnd)
    {
    m_ieHwnd = ::FindWindowEx(m_ieHwnd, 0, "Internet Explorer_Server", NULL);
    }else
    m_ieHwnd = NULL;
    }
      

  4.   

    IE 窗口总共三层,用spy++看看就知道了,要取最里面的那个