How to Put an Icon in a Menu Item Using ToolBox Statement (58677)
The information in this article applies to:
- Microsoft QuickBASIC Compiler for the Apple 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:
Also, see Chapter 11 of "Inside Macintosh, Volume I" 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 "i"
'Clear old menu bar
ClearMenuBar% = &HA934
ToolBox "PQ", ClearMenuBar%
'Get handle for new menu
mh& = 0
id% = 1
NewMenu% = &HA931
ToolBox "LQ", NewMenu%, id%, "Test", mh&
'Insert menu into menu bar
after% = 0
InsertMenu% = &HA935
ToolBox "PQ", InsertMenu%, (mh&), (after%)
'***** Add item with icon to menu
'NOTE: Icon should have id of 256+n for "Mytest^n"
' 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 "PQ", AppendMenu%, (mh&), "Mytest^1"
'Draw new menu bar
DrawMenuBar% = &HA937
ToolBox "PQ", DrawMenuBar%
'Wait for a mouse click to end program
WHILE MOUSE(0) <> 1 : WEND
Modification Type: | Minor | Last Reviewed: | 1/8/2003 |
---|
Keywords: | KB58677 |
---|
|