Microsoft KB Archive/58677

= How to Put an Icon in a Menu Item Using ToolBox Statement =

Article ID: 58677

Article Last Modified on 1/8/2003

-

APPLIES TO


 * Microsoft QuickBasic Compiler for Macintosh 1.0

-



This article was previously published under Q58677



SUMMARY
In Microsoft QuickBASIC Version 1.00 for the Apple Macintosh, the MENU statement does not support all forms of menus possible in the current Macintosh systems. For example, it is not possible to place an icon in a menu using BASIC's MENU statement, even though the Macintosh Menu Manager supports this feature. However, it is possible to access the Macintosh Menu Manager directly with BASIC's ToolBox statement.

The example below shows how to use the ToolBox statement to call the Menu Manager, create a menu, and then display the menu with an icon in that menu. The icon displayed should be an existing ICON resource in either the source file, the application file, or the System file.

This information applies to Microsoft QuickBASIC Version 1.00 for the Apple Macintosh.



MORE INFORMATION
For more information on programming menus using the Toolbox routines, there is another Knowledge Base article that shows how to create pop-up menus. This article can be found by querying on the following words:

ToolboxNEWTOOL pop-up

Also, see Chapter 11 of &quot;Inside Macintosh, Volume I&quot; by Apple Computer, published by Addison-Wesley.

The following code example creates a menu and displays an icon with ID 257 in that menu. When working inside the QuickBASIC interpreter, this icon can be in the ICON resource of either the System file or the source file. When working with a compiled application, the ICON resource should be placed into the resource fork of the application file.

NOTE: This program does not process any menu messages, and thus lacks full functionality. Detecting which menu option was selected must be done by polling the mouse position with a QuickBASIC statement, such as GetMouse. Neither QuickBASIC's ON MENU GOSUB event trapping nor the GetNextEvent system trap will trap menu events for the method used in this program.

[This program's method can't use QuickBASIC's ON MENU GOSUB to trap the menu events because the ToolBox statement in this program makes menus incompatible with ON MENU GOSUB. QuickBASIC also does not allow programs to use the Macintosh ROM routine GetNextEvent because QuickBASIC traps all events and empties out the event queue before it allows a ToolBox GetNextEvent call to act upon them. GetNextEvent always returns a value of FALSE (zero) because the event queue is cleared by QuickBASIC.]

Code Example (Incomplete: performs no action when menu is selected.)
'*** Creating menu with icon in it using ToolBox calls ToolBox &quot;i&quot;

'Clear old menu bar ClearMenuBar% = &HA934 ToolBox &quot;PQ&quot;, ClearMenuBar%

'Get handle for new menu mh& = 0 id% = 1 NewMenu% = &HA931 ToolBox &quot;LQ&quot;, NewMenu%, id%, &quot;Test&quot;, mh&

'Insert menu into menu bar after% = 0 InsertMenu% = &HA935 ToolBox &quot;PQ&quot;, InsertMenu%, (mh&), (after%)

'***** Add item with icon to menu 'NOTE: Icon should have id of 256+n for &quot;Mytest^n&quot; '     For icons with ids > 265, use ASC(n)-ASC(0) '     The icon resource can be in System file, Source file, or '        compiled application. AppendMenu% = &HA933 ToolBox &quot;PQ&quot;, AppendMenu%, (mh&), &quot;Mytest^1&quot;

'Draw new menu bar DrawMenuBar% = &HA937 ToolBox &quot;PQ&quot;, DrawMenuBar%

'Wait for a mouse click to end program WHILE MOUSE(0) <> 1 : WEND

Additional query words: MQuickB

Keywords: KB58677

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.