DTAS Popup Menu Object

Warning: Microsoft Research reserves the right to alter, enhance or rescind any of these interfaces and capabilities at any time. Neither it nor Microsoft Corporation is liable for any loss or damages attendant to using the current interfaces nor any changes to such interfaces. All such usage is entirely unsupported.

Overview

The Popup Menu object is a non-graphical control that makes popup menus easy from Visual Basic or other automation languages.

The basic interface involves creating a collection of menu items identified by strings. When created, each menu item is treated as a path string where each level of the path is a parent menu item. For example, consider the following strings.

Added as menu items to a DTASMenu object, these strings would create two top-level menu items, "Run" and "Stop". The "Run" menu item would have two child menu items, "Test One" and "Test Two".

You can set the character to be used as a path character. Parent menu items must exist before children can be added.

When you add a menu item, the return value is a unique integer index that can be used to control the items properties, such as Enabled, Bold or Checked.

Methods

Clear

Public Sub Clear()

Remove all items from the popup menu

AddItem

Public Function AddItem(ByVal sText as String, Optional vtData as Variant) as Long

Add an item, along with an optional value which may be any Visual Basic datum that can be represented as a Variant.. The return value is a unique integer identifier for the item added. This identifier will be one or greater.

DeleteItem

Public Sub DeleteItem( ByVal iItemIndex as Long)

Popup

Public Function Popup(Optional iLeft as Long, Optional iTop as Long) As Integer

Perform the menu popup operation. Returns the index of the menu item chosen or zero if no item was selected.

Properties

Object (Menu Collection) Properties

Name

Data Type

Purpose

PathCharacter

String

Set the menu path name separator character; default value is backslash ("\")

Count

Long

Returns the number of menu items in the collection.

TrackingFlags

Long

Sets the popup menu tracking flags used by the Windows TrackPopupMenu API.

SeparatorCharacter

String

Set the character used in menu paths to indicate a menu separator; default value is vertical bar ("|")

Menu Item Properties

Menu item properties are indexed by the long integer value returned from the AddItem function and apply only to that unique menu item.

Name

Data Type

Purpose

Checked

Boolean

Determines if a check mark appears next to the menu item.

Bold

Boolean

Determines if the text for the menu item is in boldface.

Text

String

The text string displayed in the menu item.

Enabled

Boolean

Determines if the menu item is in normal or greyed text.

ItemData

Long

Sets or returns a long integer value associated with the menu item.

ItemVisible

Boolean

Determines if the item is visible when the menu is displayed.

Parent

Long

Returns the unique item index of the parent menu item for this item.

Reference

Variant

Sets or returns the Variant datum given when the item was created.