코딩하는 나귀

C++ 코드 :



#include
<shlguid.h>

HWND GetTabWnd(CComQIPtr<IWebBrowser2> spBrowser)
{
HWND hwndTab = NULL;
CComQIPtr<IServiceProvider> spServiceProvider = spBrowser;

if (spServiceProvider != NULL)
{
CComQIPtr<IOleWindow> spWindow;
if (SUCCEEDED(spServiceProvider->QueryService(
SID_SShellBrowser,
IID_IOleWindow,
(void**)&spWindow)))
{

spWindow->GetWindow(&hwndTab));
}
}

return hwndTab;
}
델파이 코드 :
const
 
SID_SShellBrowser: TGUID = '{000214E2-0000-0000-C000-000000000046}';
  IID_IOleWindow : TGUID = '{00000114-0000-0000-C000-000000000046}';



function GetTabWnd(spBrowser: IWebBrowser2): HWND;
var
hwndTab: HWND;
spServiceProvider: IServiceProvider;
spWindow: IOleWindow;
begin



spServiceProvider := spBrowser as IServiceProvider;
if (SUCCEEDED(spServiceProvider.QueryService(SID_SShellBrowser,
IID_IOleWindow,
spWindow) then
begin
spWindow.GetWindow(hwndTab);
end;
result hwndTab;
end