Microsoft Dynamics AX 4
Modify the Shortcut Menu on Form Controls

The shortcut menu on controls appears when a user right-clicks on a form control. The content of the menu is controlled by the system and is defined according to the current context.

The following figure is an example of a shortcut menu.

Aa674954.37f3e9db-6cc6-4a1b-95d5-9c1b11b32c9a(en-US,AX.10).gif

When the user right-clicks a control, the context method for the control is called, and its super() call calls the showContextMenu method. The parameter to showContextMenu is a handle to the system’s shortcut menu.

Use showContextMenu to add your own item to the shortcut menu.

Example

int showContextMenu(int MenuHandle)
{
    int ret;
    PopupMenu m = PopupMenu::create(MenuHandle,this.hWnd());
 
    // Save the handle of the appended menu item.
    int myMenuItem = m.insertItem("MyItem");
    ;   
    // Display the menu.
    ret   = m.draw(); 
 
    // Check if the user selected myMenuItem.
    if   (ret == myMenuItem) 
    {
        print   "MyItem was selected";
        pause;
        return   0;
    }
    else
    return ret;
}

Note that the draw method is called instead of super().

The showContextMenu method should return the user’s selection if the system should take a menu action based on the selection, or zero (0) if no action should be taken.

Page view tracker