Microsoft KB Archive/238587

= FIX: Keyboard Input Beeps in Applet in Browser Control Hosted in MFC Application =

Article ID: 238587

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Java Virtual Machine
 * Microsoft Software Development Kit for Java 3.2
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q238587



SYMPTOMS
While hosting a Java applet in a Microsoft Foundation Classes (MFC) application with a View class derived from CHtmlView class, keyboard input to the applet causes the system to beep.



CAUSE
This is caused by a bug in Microsoft virtual machine (Microsoft VM) builds earlier than 3186.



RESOLUTION
Update your version of the Microsoft VM to build 3186 (or later), which is available for download at the following Web site:

http://www.microsoft.com/mscorp/java/

-or-

Perform the workaround listed at the end of the MORE INFORMATION section.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Microsoft VM build 3186 and later.



Steps to Reproduce Behavior
  Create a file KeyInputApplet.java with the following code: import java.awt.*; import java.applet.*;

public class KeyInputApplet extends Applet {   public void init {       setLayout(new BorderLayout); TextArea ta = new TextArea; add(ta, BorderLayout.CENTER); Button b = new Button("Set focus and push [ENTER]"); add(b, BorderLayout.SOUTH); doLayout; } }                        Compile KeyInputApplet.java using the following command:

jvc KeyInputApplet.java   Create an HTML page called Test.html with the following tags:

This is an applet 



The following steps illustrate how to use this applet from an MFC single-document interface (SDI) application and also reproduce the problem:  Using Visual C++ 6.0, create an MFC SDI application using all the default options.</li> Make sure your View class is derived from CHtmlView.</li>  Modify the Navigate2 method of the OnInitialUpdate method as follows, with the first argument of this method pointing to the Test.html file that you created earlier. The code assumes that you created the Test.html in a folder called C:\KeyInput. void CTestView::OnInitialUpdate {   CHtmlView::OnInitialUpdate;

// TODO: This code navigates to a popular spot on the web. // change the code to go where you'd like. Navigate2(_T("C:\\KeyInput\\Test.html"),NULL,NULL); }

</li> Compile this project and run the generated executable file.</li> The SDI application will load the Test.html file in the client area, which displays the applet.</li> Click in the text field and input some text.</li> You will hear a beep for each key stroke of input.</li></ol>

Workaround
If you are using a Microsoft VM build earlier than 3186, then you can work around the problem by overriding the PreTranslateMessage in the CHtmlView-derived class as follows: BOOL CPlainView::PreTranslateMessage(MSG* pMsg) {

//This is the workaround char classname[255]; ::GetClassName(pMsg->hwnd, classname, 255); if (pMsg->message == WM_CHAR) {       if (stricmp(classname,"MSAWT_Comp_Class") == 0) return TRUE; }

return CHtmlView::PreTranslateMessage(pMsg); }

<div class="references_section">