As I've said in other questions, I'm contributing to an open-source browser automation framework (Selenium WebDriver), and having difficulty with IE. The framework uses an external process written in C++, not a Browser Helper Object (BHO). Clicks on elements are generated using Windows messages (WM_LBUTTONDOWN and WM_LBUTTONUP) rather than simulated clicks through COM. Justification for this design decision can be found in the project's wiki here.
In order to determine if a navigation has started, the driver code is attached to the DWebBrowserEvents2::BeforeNavigate2 event. After the click messages are sent to the IE window, however, there is some delay between when SendMessage returns (indicating the IE message loop has processed the message), and when BeforeNavigate2 fires. I suppose I could use attachEvent to attach a callback function to the onclick event of the HTML element and wait for that to be processed, but I'm not sure if that would be synchronous to the BeforeNavigate2 event.
Without calling the Windows Sleep() function for an arbitrary amount of time, how can I wait for the BeforeNavigate2 event after sending a mouse click simulated by Windows messages?