FIX: Keyboard Input Beeps in Applet in Browser Control Hosted in MFC Application
ID: Q238587
|
The information in this article applies to:
-
Microsoft virtual machine
-
Microsoft Visual Studio 6.0
-
Microsoft SDK for Java, version 3.2
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:
SDK Updates - Microsoft Technologies for 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.
MORE INFORMATION
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:
<html>
<body>
<p> This is an applet <p>
<applet
code=KeyInputApplet.class
width=400
height=100>
</applet>
</body>
</html>
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.
- Make sure your View class is derived from CHtmlView.
- 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);
}
- Compile this project and run the generated executable file.
- The SDI application will load the Test.html file in the client area, which displays the applet.
- Click in the text field and input some text.
- You will hear a beep for each key stroke of input.
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);
}
REFERENCES
The latest Microsoft VM is available for download at the following Web site:
SDK Updates - Microsoft Technologies for Java
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 Venkat Sunkara, Microsoft Corporation
Additional query words:
Keywords : kbJavaVM kbVS600bug kbGrpJava kbDSupport kbSDKJava320bug
Version : WINDOWS:3.2,6.0
Platform : WINDOWS
Issue type : kbbug