If this is being used in a control, you probably need one extra "out" param used by the control window framework in pythonwin. In my code, I've been unable to effectively cancel the OnBeforeNavigate2 event though, but I don't think its related to pywin32. I could get the OnNewWindow3 event to cancel though, with code like:
def OnNewWindow3(self, ppDisp, Cancel, dwFlags, bstrUrlContext, bstrUrl): #print "NewWindow", `bstrUrlContext`, `bstrUrl` if i_want_to_cancel_it: # cancel the event return 0, None, True That first out param is the extra one I referred to above, and I can't recall what the 2nd out param is but the 3rd is 'Cancel' Hope this helps, Mark > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:python-win32- > [EMAIL PROTECTED] On Behalf Of Vaclav Opekar > Sent: Sunday, 8 June 2008 9:47 PM > To: python-win32@python.org > Subject: [python-win32] IE control via DWebBrowserEvents2 > > Hello all, > I'm trying to embed IE to a GTK app and control IE behavior via the > DWebBrowserEvents2 interface. > Embedding works, events like OnBeforeNavigate2 or OnNewWindow2 are > comming fine but when I try to return (from the callback) a Cancel > value which suppose stop IE from next page loading or new explorer > window creation, the program either crashes or doesn't prevent IE from > moving to next page or opening a new window. > > Any idea how I could approach this problem? > > Bellow are details and code snippets. > > Thanks a lot, > Vasek > > ->I've used this example as a base > http://pywin32.cvs.sourceforge.net/pywin32/pywin32/com/win32comext/axco > ntrol/demos/container_ie.py?revision=1.2&view=markup > > ->generated the stubs using > python makepy.py C:\WINDOWS\system32\shdocvw.dll > > ->defined callback class using the generated classes > (DWebBrowserEvents2) > class BrowserCB(DWebBrowserEvents2): > def __init__(self, oobj): > DWebBrowserEvents2.__init__(self, oobj) > > #Cancel is in/out param in COM > def OnBeforeNavigate2(self, pDisp, URL, Flags, TargetFrameName, > PostData, Headers, Cancel): > if URL != "about:blank" : > # return 1 # <- this crashes IE > return True # this doesnt work - doesn stop IE to move to > non blank page > > # Cancel is in/out param in COM > def OnNewWindow2(self, ppDisp=defaultNamedNotOptArg, > Cancel=defaultNamedNotOptArg): > print "OnNewWindow2" > return True # returns pythoncom error: Python error invoking > COM > method. > > > -> callback class registration snippet > browser.DoVerb(axcontrol.OLEIVERB_SHOW, None, site, -1, > self.hwnd, rect) > b2 = Dispatch(browser.QueryInterface(pythoncom.IID_IDispatch)) > self.browser2 = b2 > self.eventSink = BrowserCB(self.browser2) #only this line was > added to the above example from CVS > > _______________________________________________ > python-win32 mailing list > python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32