Important: The information in this document is obsolete and should not be used for new development.
MenuSelect
Use theMenuSelectfunction to allow the user to choose a menu item from the menus in your application's menu bar.
FUNCTION MenuSelect (startPt: Point): LongInt;
startPt- The point (in global coordinates) representing the location of the cursor at the time the mouse button was pressed.
DESCRIPTION
When the user presses the mouse button while the cursor is in the menu bar, your application receives a mouse-down event. To handle mouse-down events in the menu bar, pass the location of the cursor at the time of the mouse-down event as thestartPtparameter toMenuSelect. TheMenuSelectfunction displays and removes menus as the user moves the cursor over menu titles in the menu bar, and it handles all user interaction until the user releases the mouse button.As the user drags the cursor through the menu bar, the
MenuSelectfunction highlights the title of the menu the cursor is currently over and displays all items in that menu. If the user moves the cursor so that it is over a different menu, theMenuSelectfunction removes the previous menu and unhighlights its menu title.The
MenuSelectfunction highlights and unhighlights menu items as the user drags the cursor over the items in a menu. TheMenuSelectfunction highlights a menu item if the item is enabled and the cursor is currently over it; it removes such highlighting when the user moves the cursor to another menu item. TheMenuSelectfunction does not highlight disabled menu items.If the user chooses an enabled menu item (including any item from a submenu), the
MenuSelectfunction returns a value as its function result that indicates which menu and menu item the user chose. The high-order word of the function result contains the menu ID of the menu, and the low-order word contains the item number of the menu item chosen by the user. TheMenuSelectfunction leaves the menu title highlighted; after performing the chosen task your application should unhighlight the menu title using theHiliteMenuprocedure.If the user chooses an item from a submenu,
MenuSelectreturns the menu ID of the submenu in the high-order word and the item chosen by the user in the low-order word of its function result. TheMenuSelectfunction also highlights the title of the menu in the menu bar that the user originally displayed in order to begin traversing to the submenu. After performing the chosen task, your application should unhighlight the menu title.If the user releases the mouse button while the cursor is over a disabled item, in the menu bar, or outside of any menu, the
MenuSelectfunction returns 0 in the high-order word of its function result and the low-order word is undefined. If it is necessary for your application to find the item number of the disabled item, your application can callMenuChoiceto return the menu ID and menu item.If the user chooses an enabled item in a menu that a desk accessory has inserted into your application's menu list,
MenuSelectuses theSystemMenuprocedure to process this occurrence and returns 0 to your application in the high-order word.SPECIAL CONSIDERATIONS
When theMenuSelectfunction pulls down a menu, it stores the bits behind the menu as a relocatable object in the application heap of your application.ASSEMBLY-LANGUAGE INFORMATION
TheInitMenusandInitProcMenuprocedures initialize theMenuHookandMBarHookglobal variables to 0. If you choose, you can store the addresses of routines thatMenuSelectcalls in these global variables. TheMenuHookglobal variable contains the address (if any) of a routine thatMenuSelectcalls repeatedly while the mouse button is down.MenuSelectdoes not pass any parameters to this routine.The
MBarHookglobal variable contains the address (if any) of a routine thatMenuSelectcalls after a menu title is highlighted and the menu rectangle is calculated but before the menu is drawn. The menu rectangle is the rectangle (in global coordinates) in which the menu will be drawn.MenuSelectpasses a pointer to the menu rectangle on the stack. If you provide the address of a routine in theMBarHookglobal variable, it should normally return 0 in the D0 register, indicating thatMenuSelectshould continue; returning 1 causesMenuSelectto cancel its operation and return immediately to the application.The
MenuSelectfunction uses the global variableMBarEnableto determine if all menus in the current menu bar belong to a desk accessory or an application. If theMBarEnableglobal variable is nonzero, then all menus in the current menu bar belong to a desk accessory. If theMBarEnableglobal variable is 0, then all menus in the current menu bar belong to an application. If you're writing a desk accessory, you may need to set theMBarEnableglobal variable to a nonzero value; if you're writing an application, you should not change the value of theMBarEnableglobal variable.The global variable
TheMenucontains the ID of the currently highlighted menu in the menu bar. If the user chooses an item from a submenu,TheMenucontains the menu ID of the submenu, not the menu to which the submenu is attached.SEE ALSO
For information on adjusting your application's menus before callingMenuSelect, see "Adjusting the Menus of an Application" beginning on page 3-73.See the description of the
HiliteMenuprocedure on page 3-121 for details on how to unhighlight a menu. For information on how to determine if the user chose a disabled item, see the description of theMenuChoicefunction on page 3-120.