Microsoft KB Archive/223370

= FIX: Enter/Leave Events Are Not Getting Fired in Code-Behind HTML =

Article ID: 223370

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Java Virtual Machine
 * Microsoft Visual J++ 6.0 Standard Edition

-



This article was previously published under Q223370



SYMPTOMS
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.



STATUS
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

 * 1) Compile and run the following code.
 * 2) 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.
 * 3) Now, click on the dynamic (lower) button. This will bring up a WFC Form with two more buttons wired to the same event handlers.
 * 4) Tab between the controls (buttons) in the form, and move the mouse over each button.
 * 5) 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.
 * 6) You will also see that the MouseEnter and MouseLeave events are handled in both cases.
 * 7) 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.

HTML Code
   













  </HTML>

Java Code
import com.ms.wfc.html.*; import com.ms.wfc.core.*; import com.ms.wfc.ui.*; import com.ms.wfc.html.om.*; import com.ms.com.*; import com.ms.wfc.app.*;

public class Class1 extends DhDocument {    Button wfcButtonDragDrop; Button wfcButtonDynamic; EventHandler enter = new EventHandler(onEnter); EventHandler leave = new EventHandler(onLeave); EventHandler mEnter = new EventHandler(onMEnter); EventHandler mLeave = new EventHandler(onMLeave); public Class1 {      initForm; wfcButtonDynamic = new Button; wfcButtonDynamic.setSize(250, 50); wfcButtonDynamic.setText("WFC Button Dynamic"); wfcButtonDynamic.addOnEnter(enter); wfcButtonDynamic.addOnLeave(leave); wfcButtonDynamic.addOnMouseEnter(mEnter); wfcButtonDynamic.addOnMouseLeave(mLeave); wfcButtonDynamic.addOnClick(new EventHandler(onClick)); DhComponentWrapper bwrap = new DhComponentWrapper(wfcButtonDynamic); bwrap.setSize(250, 50); add(bwrap); }

public void dispose {      super.dispose; }

private void initForm {    }

protected void onDocumentLoad(Object sender, Event e)     { //DhElement tmp = this.findElement("wfcButton"); //ClassCastException because IHTMLElement is not //exposed for WFC Controls IHTMLDocument2 doc = (IHTMLDocument2)getPeer; IHTMLElementCollection all = doc.getAll; wfcButtonDragDrop = (Button)all.item(new Variant("wfcButton"),                                           new Variant(0)); wfcButtonDragDrop.addOnEnter(enter); wfcButtonDragDrop.addOnLeave(leave); wfcButtonDragDrop.addOnMouseEnter(mEnter); wfcButtonDragDrop.addOnMouseLeave(mLeave); }    private void onEnter(Object source, Event e)     { ((Button)source).setText("Enter"); }    private void onLeave(Object source, Event e)     { ((Button)source).setText("Leave"); }    private void onMEnter(Object source, Event ev) {      ((Button)source).setText("Mouse Enter"); }    private void onMLeave(Object source, Event ev) {      ((Button)source).setText("Mouse Leave"); }    private void onClick(Object source, Event ev) {      Button b1 = new Button; b1.setDock(ControlDock.TOP); b1.addOnEnter(enter); b1.addOnLeave(leave); b1.addOnMouseEnter(mEnter); b1.addOnMouseLeave(mLeave); Button b2 = new Button; b2.addOnEnter(enter); b2.addOnLeave(leave); b2.addOnMouseEnter(mEnter); b2.addOnMouseLeave(mLeave); b2.setDock(ControlDock.BOTTOM); Form f = new Form; f.setBackColor(Color.WHITE); f.setSize(400, 400); f.add(b1); f.add(b2); Application.run(f); }  }

<div class="references_section">