Parameter | Description |
---|---|
hoControls | A proxy object of the parent menu's cCJCommandControls collection object |
Returns a variant pointer to the COM control created
Function AddDynamicControl Handle hoControls Returns Variant
Call: | Get AddDynamicControl hoControls to VariantVariable |
AddDynamicControl provides a way to add a dynamic menu item to a popup menu. This is usually called within the [OnPopupInit event as a popup menu is about to be displayed. If a new item needs to be added to the menu, you will create the menu object and call AddDynamicControl. This entire process is discussed in OnPopupInit.
This message is sent to the object that should be added as a new item and it is passed a pointer to its popup parent. It is passed the parent's cCJCommandBarControls proxy object. The cCJCommandBarControls object is a collection object representing all of the child COM controls in the popup. It is passed in to OnPopupInit and should be passed to AddDynamicControl.
The process of adding a new dynamic control consists of:
1. Creating the new cCJMenuItem control object.
2. Setting any properties required for this new object
3. Sending AddDynamicControl to the new object passing a pointer to the cCJCommandBarControls object.
Procedure OnPopupInit Variant vCommandBarControl Handle hCommandBarControls Handle hoNewItem Variant vItem : // create the new control based on cCJMenuItem or a sub class of it. Get Create U_cCJMenuItem to hoNewItem // set whatever properties are needed for this object. Set psCaption of hoNewItem to "Some Caption" // dynamically add the menu as a child of the current popup. Get AddDynamicControl of hoNewItem hCommandBarControl to vItem : End_Procedure
A complete example, which shows how to create sub-classes, remove old items and create new items, is provided in OnPopupInit. In addition, refer to the Using Menus, Toolbars and Statusbars section for more about creating dynamic menus.
If the control cannot be created, a programming error has occurred and an error will be raised.