MSHTML IWebBrowser2 - Downgrading page events cause missed keystrokes?

I have a problem with my application using MSHTML. I have everything that works, except that there is not enough odd keystroke behavior when typing as indicated in the subject line. I think it might have something to do with the method I am using to sink events?

Details: My application is a standalone program written in C ++ and MFC in Visual Studio 2005. The program attaches to the current (independent) instance of Internet Explorer and gets an interface pointer IWebBrowser2

and passes it to an object of type CCmdTarget

:


class CHandler : public CCmdTarget
{
  IWebBrowser2* m_pWebBrowser2;
  DWORD m_dwBrowserCookie;
  DECLARE_DISPATCH_MAP()
};

      

This class keeps track of what is happening in the browser. I have broken browser events with the following command:


LPUNKNOWN pUnkSink = GetIDispatch(FALSE);
retval = AfxConnectionAdvise((LPUNKNOWN)m_pWebBrowser2, DIID_DWebBrowserEvents2, pUnkSink, FALSE, &m_dwBrowserCookie);

      

If I comment AfxConnectionAdvise

, then no keystrokes will be missed, but no more events. If I leave this I am omitting the events, but I cannot notice the accidental key press while fast typing.

I know there are several ways to connect to events ( AtlAdvise

, connection points), but this was the only one I could work with.

Any suggestions would be great!

0


a source to share


2 answers


If you're just looking for keystrokes, can you subclass the control?



0


a source


Under the covers all the different hookup methods ( AtlAdvise

, AfxConnectionAdvise

etc) use IConnectionPointContainer

and IConnectionPoint

- they just keep you typing the COM goo template.



I suspect it has something to do with the way you connect to the IE executable instance. How do you get the pointer IWebBrowser2

? Are you booting into an IE process or are you running a separate process? If you are using a different thread than the original thread IWebBrowser2

(IE UI thread), are you doing the correct COM collation?

0


a source







All Articles