[python-win32] How to get IWebBrowser2 from a HWND
Tim Golden
mail at timgolden.me.uk
Fri Jul 11 12:27:13 CEST 2008
salvatore ventura wrote:
> Hi,
> I am trying to get the IWebBrowser2 object from the HWND of an open IE window.
[... snip complex code ...]
At the risk of oversimplifying matters (and thanks to Roger
Upole for providing this snippet which I think I've linked to
three times this week!):
<code>
import win32com.client
HWND = 0x00bd031e
ShellWindows_guid = '{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'
for shell_window in win32com.client.Dispatch (ShellWindows_guid):
if hasattr (shell_window, "HWND") and shell_window.HWND == HWND:
web_browser = shell_window
break
else:
web_browser = None
if web_browser:
print "browser at", web_browser.LocationURL
else:
print "Couldn't find browser at hwnd", HWND
</code>
TJG
More information about the python-win32
mailing list