PRB: Context Menu Is Not Displayed Correctly on Windows NT4.0 (297032)
The information in this article applies to:
- Microsoft Visual J++ 6.0, when used with:
- the operating system: Microsoft Windows NT 4.0
- the operating system: Microsoft Windows NT 4.0 SP6a
This article was previously published under Q297032 SYMPTOMS
On a Windows NT 4.0-based computer, if a user right-clicks a node in a Visual J++ project that includes a basic TreeView control and then right-clicks another node, the original node is still selected, and the context menu does not change (or is not hidden).
Normally, when you right-click a node, a context menu appears. When you right-click another node, the new node should be selected, and the new context menu should appear. However, this does not occur on Windows NT 4.0.
CAUSE
This problem occurs because of a change in the default behavior of the Win32 TrackPopupMenuEx function to include button clicks outside the context menu, but not on the TreeView control.
RESOLUTION
To resolve this problem, subclass the ContextMenu control, and override the show method to call TrackPopupMenuEx with both the TPM_VERTICAL and TPM_RIGHTBUTTON flags set.
To preserve the ability to render the form in the Windows Foundation Classes for Java (WFC) Designer, you must also provide the nested ClassInfo class.
This is a complete listing of the subclassed ContextMenu.
import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.win32.*;
import com.ms.wfc.html.*;
public class ContextMenuNT4 extends ContextMenu
{
public ContextMenuNT4()
{
super();
}
public void show(Control control, Point pos)
{
if (control == null)
throw new WFCInvalidArgumentException(Sys.getString("InvalidArgument",
"control",
"null"));
if (!control.getHandleCreated() || !control.getVisible())
throw new WFCException(Sys.getString("ContextMenuInvalidParent"));
onPopup(Event.EMPTY);
pos = control.pointToScreen(pos);
Win32.TrackPopupMenuEx(getHandle(),
win.TPM_VERTICAL | win.TPM_RIGHTBUTTON,
pos.x,
pos.y,
control.getHandle(),
null);
}
//Include this section so that control works well with WFC Designer.
public static class ClassInfo extends Menu.ClassInfo
{
public static final EventInfo popup = new EventInfo(
ContextMenuNT4.class, "popup", EventHandler.class,
new DescriptionAttribute(Sys.getString("MenuItemOnInitDescr")));
public void getEvents(IEvents events)<BR/>
{
super.getEvents(events);
events.add(popup);
}
}
}
REFERENCES
For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:
Modification Type: | Major | Last Reviewed: | 6/14/2006 |
---|
Keywords: | kbCmnCtrls kbprb kbWFC KB297032 |
---|
|