Hi Mark,
 thanks for helping out. I have tried the same QueryInterface but this time on 
the 'main' window (no popup open), this time looking for the 'IEFrame' class, 
and then following the same steps as in my popup example, but this time, the 
QueryInterface seems to happily return a 'number'. I couldn't figure out what 
that number is (handle? pointer? to what?). Here the code:

win1 = win32gui.FindWindow('IEFrame', 'Test main page - Windows Internet 
Explorer') #IE window handle
win1 = winGuiAuto.findControl(win1, None, 'Internet Explorer_Server', None)     
    # get the 'Internet Explorer_Server 

# get the IHTMLDocument2 of the popup dialog
oleacc = oledll.LoadLibrary ( 'oleacc.dll' )
WM_HTML_GETOBJECT = windll.user32.RegisterWindowMessageA ('WM_HTML_GETOBJECT' )
lResult = c_ulong ( )
ret = windll.user32.SendMessageTimeoutA ( c_int ( win1 ), c_int 
(WM_HTML_GETOBJECT),c_int ( 0 ), c_int ( 0 ), c_int ( SMTO_ABORTIFHUNG ), c_int 
( 1000 ), byref (lResult ) )
pIHTMLDocument2 = POINTER ( IHTMLDocument2 ) ( )
oleacc.ObjectFromLresult ( lResult, byref ( IHTMLDocument2._iid_ ), 0,byref 
(pIHTMLDocument2 ) ) # title of the page verifies
ihtmlwin = pIHTMLDocument2.parentWindow

# and the IServiceProvider
pIServiceProvider = POINTER ( IServiceProvider ) ()
pIServiceProvider = ihtmlwin.QueryInterface(IServiceProvider, 
IServiceProvider._iid_)

ie = POINTER(IWebBrowser2) ()
ie = pIServiceProvider.QueryService(IWebBrowserApp._iid_, IWebBrowser2._iid_) # 
this one doesn't bump...



I have found my way around my problem, although with a major change in my 
approach and class structures.

One more question, that might have been already asked: the difference between 
pythoncom and ctypes. I think I am mixing them up in my code and concepts 
still...

thanks again,
.salvo



--- Ven 18/7/08, Mark Hammond <[EMAIL PROTECTED]> ha scritto:

> Da: Mark Hammond <[EMAIL PROTECTED]>
> Oggetto: RE: [python-win32] How to get IWebBrowser2 from a HWND
> A: "'salvatore ventura'" <[EMAIL PROTECTED]>, python-win32@python.org
> Data: Venerdì 18 luglio 2008, 23:36
> I dug into this a little more, but I'm afraid there
> isn't much good news to share :(
> 
> >  What I would like to achieve is the IWebBrowser2
> object of the
> > dialog.htm page. I know I can access anything on the
> page itself  via
> > the IHTMLDocument2 (which I already have) but
> that's not my  need.
> 
> I can reproduce this your problem.  I also added
> ObjectFromLresult to pywin32 - so getting the doc object
> from a HWND will (in pywin32-212) be as easy as:
> 
>     # See KB Q249232
>     hwnd = win32gui.FindWindow('IEFrame', None)
>     for child_class in ['TabWindowClass',
> 'Shell DocObject View',
>                         'Internet
> Explorer_Server']:
>         hwnd = win32gui.FindWindowEx(hwnd, 0, child_class,
> None)
>     msg =
> win32gui.RegisterWindowMessage("WM_HTML_GETOBJECT")
>     rc, result = win32gui.SendMessageTimeout(hwnd, msg, 0,
> 0, win32con.SMTO_ABORTIFHUNG, 1000)
>     ob = pythoncom.ObjectFromLresult(result,
> pythoncom.IID_IDispatch, 0)
>     doc = Dispatch(ob)
>     doc.bgColor = "red"
> 
> (The above is the simple case - I understand your example
> was more complex due to the modal dialog).  But as you
> said, you are already at that point with ctypes, and we
> move into your problem.  From the code above, pywin32 can
> take over - it already has native support for
> IServiceProvider - so, something like the following, from
> your failing sample.
> 
>     ihtmlwin = doc.parentWindow
>     # ... the service provider ...
>     pIServiceProvider =
> ihtmlwin._oleobj_.QueryInterface(pythoncom.IID_IServiceProvider)
>     # ... and the IWebBrowser2:
>     ie = pIServiceProvider.QueryService(IID_IWebBrowserApp,
> IID_IWebBrowserApp)
> 
> And the problem I see is that QueryService *always* fail
> with E_NOINTERFACE, regardless of the interface requested
> as the second param.  Even IUnknown fails, which
> doesn't make sense, so my conclusion is that the object
> is simply refusing to return that service (rather than
> failing to return the interface for the service).  The docs
> imply IE should indeed work here, so I suspect the issue
> relates specifically to the modal window. I'm afraid I
> ran out of time on this issue to confirm the QueryService
> worked in the "normal" case - I just got far
> enough to ensure myself the problem wasn't related to
> Python ;)
> 
> Hope your are progressing regardless ;)
> 
> Cheers,
> 
> Mark
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to