Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Hosting and Reuse
WebBrowser Control
Interfaces
IWebBrowser2
 HWND Property

  Switch on low bandwidth view
IWebBrowser2::HWND Property

Gets the handle of the Windows Internet Explorer main window.

Syntax

HRESULT IWebBrowser2::get_HWND(long *pHWND);

Parameters

pHWND
Pointer to a variable of type long that receives the window handle.

Return Value

Returns S_OK if successful, or an error value otherwise.

Remarks

Internet Explorer 7. With the introduction of tabbed browsing, the return value of this method can be ambiguous. To alleviate confusion and maintain the highest level of compatibility with existing applications, this method returns a handle to the top-level window frame, not the currently selected tab.

Example

For applications that absolutely require an HWND to the current tab, the following example returns the same logical window as IWebBrowser2::HWND in a previous version of Internet Explorer. This technique works equally well in both Internet Explorer 7 and Microsoft Internet Explorer 6.

#include <shlguid.h>

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();
} 
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Showing a modal dialog can use either the frame or the tab      Sheng Jiang 蒋晟 ... Raymond Chen MS   |   Edit   |   Show History
See Modality, part 4: The importance of setting the correct owner for modal UI (http://blogs.msdn.com/oldnewthing/archive/2005/02/23/378866.aspx)
--
The cited article is irrelevant. The tab handle and the frame handle are equivalent for this purpose since one is a child of the other. -Raymond
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker