This article was previously published under Q223370
When using Windows Foundation Classes (WFC) controls on a Web page, while it is possible to add OnEnter and OnLeave event handlers (delegates), the events do not actually fire, and the handler methods do not get called.
Microsoft has confirmed that this is a problem in versions of Microsoft Visual J++.
This bug was corrected in Visual Studio 6.0 Service Pack 3. For more information about Visual Studio service packs, please see the following articles in the Microsoft Knowledge Base:
194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why
194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed
Steps to Reproduce Behavior
Compile and run the following code.
In Internet Explorer, move the mouse over each button, and tab between the two buttons. You will notice that nothing happens when tabbing between the buttons (these would be the Enter and Leave events). You will also notice that the dynamic (lower) button is not in the tab order with the other elements; it is skipped.
Now, click on the dynamic (lower) button. This will bring up a WFC Form with two more buttons wired to the same event handlers.
Tab between the controls (buttons) in the form, and move the mouse over each button.
You will notice that the enter and leave events are now firing and being handled by the delegates assigned to them. These are the same delegates that did nothing when in the context of the Web page.
You will also see that the MouseEnter and MouseLeave events are handled in both cases.
To run this test from outside the Visual J++ IDE, you need to place Class1.class in a signed CAB file called WFCUICodeBehind.cab.
NOTE: When accessing a WFC Control on a Web page from the Java code behind the HTML, you will not be able to get to it through normal means as a DhElement. DhDocument.getAllElements() or DhDocument.findElement() do not work and cause a ClassCastException to be thrown. This is because the IHTMLElement COM interface is not exposed for WFC controls used this way. This interface is required when accessing typical HTML page elements in a traditional code-behind scenario.
The way to access a WFC control (represented by an OBJECT tag and clsid:java: ... in HTML) is through the DOM or Document Object Model. You do this by obtaining the IHTMLDocument2 interface for the DhDocument object and using methods exposed by that interface to retrieve the IDispatch interface for the WFC Control object. Typecast the dispatch interface to the Java WFC Control class (Button in this case) to use it as a WFC Java object.