如何获得IWebBrowser2的Internet Explorer
发布网友
发布时间:2023-07-12 07:10
我来回答
共1个回答
热心网友
时间:2024-12-03 18:52
#include <ShlGuid.h>
HWND GetHwndFromIWebBrowser2(IWebBrowser2* pWebBrowser2)
{
if (pWebBrowser2 == NULL)
return NULL;
IServiceProvider* pServiceProvider = NULL;
//1. --Shell Embedding
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)))
{
//2.|-Shell DocObject View
HWND hchildwnd = GetWindow(hwndBrowser, GW_CHILD);
while (hchildwnd)
{
TCHAR wndname[MAX_PATH] = _T("");
GetClassName(hchildwnd, wndname, MAX_PATH);
if ( wcscmp(wndname,_T("Shell DocObject View")) == 0 )
{
//3.|--Internet Explorer_Server
HWND hiewnd = GetWindow(hchildwnd, GW_CHILD);
while (hiewnd)
{
TCHAR wndname[MAX_PATH] = _T("");
GetClassName(hiewnd, wndname, MAX_PATH);
if ( wcscmp(wndname,_T("Internet Explorer_Server")) == 0 )
{
return hiewnd;
}
hiewnd = GetNextWindow(hiewnd, GW_HWNDNEXT);
}
return hwndBrowser;
}
hchildwnd = GetNextWindow(hchildwnd, GW_HWNDNEXT);
}
return hwndBrowser;
}
pWindow->Release();
}
pServiceProvider->Release();
}
return NULL;
}