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

ID: Q223370


The information in this article applies to:
  • Microsoft virtual machine
  • Microsoft Visual J++, version 6.0


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 this to be 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:

Q194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

Q194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed


MORE INFORMATION

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>
<BODY>
<P>
<OBJECT 
     classid=java:com.ms.wfc.html.DhModule 
     height=0 
     width=0 ... 
     VIEWASTEXT>

<PARAM 
     NAME="CABBASE" 
     VALUE="WFCUICodeBehind.CAB">

<PARAM 
     NAME="__CODECLASS" 
     VALUE="Class1">

</OBJECT>

<OBJECT 
     classid=java:com.ms.wfc.ui.Button 
     height=50 
     id=Button1 
     name=wfcButton 
     style="HEIGHT: 50px; 
     LEFT: 0px; 
     TOP: 0px; 
     WIDTH: 250px"
     width=219 
     VIEWASTEXT>

<PARAM NAME="data" VALUE="UEsBAAAEc2l6ZQsAE2NvbS5tcy53ZmMudWkuUG9pbnQIAAAA+gAAADIAAAAACHRhYkluZGV4BQAAAAAABHRleHQJABhXRkMgQnV0dG9uIERyYWcgYW5kIERyb3AAAA==">

</OBJECT>
<!-- Insert HTML here -->
</P>
</BODY>
</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);
     }
   } 


REFERENCES

For more information on the IHTMLDocument2 interface, see the MSDN Online Web Workshop, or search the MSDN index for "IHTMLDocument2."

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, please see the following pages on the Microsoft Technical Support site:

http://support.microsoft.com/support/visualj/

http://support.microsoft.com/support/java/


© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Robert LaCasse, Microsoft Corporation

Additional query words:

Keywords : kbservicepack kbActiveX kbCOMt kbCtrlCreate kbide kbJava kbJavaVM KbUIDesign kbVJ600fix kbWFC kbGrpJava kbVS600sp2 kbVS600SP1 kbVS600sp3fix
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: November 16, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.