Microsoft KB Archive/39094
Article ID: 39094
Article Last Modified on 11/21/2006
This article was previously published under Q39094
You can easily cause a System Error or cause garbage in the QuickBASIC List window if you pass incorrect parameters to the TOOLBOX statement in QuickBASIC for Macintosh. (You must usually restart the Macintosh after a System bomb. ReOPENing the file often corrects the garbage in the List window.)
TOOLBOX is a powerful statement that lets you make many Macintosh ROM traps; however, you must be cautious to pass only the correct parameters to TOOLBOX.
Below is an example of how to correctly pass parameters to the TOOLBOX statement to programmatically move a window defined with the QuickBASIC WINDOW statement.
The example below shows how to invoke a ROM trap called MoveWindow with a TOOLBOX statement. MoveWindow is defined on Page 289 of Volume I of "Inside Macintosh" (published by Addison-Wesley). MoveWindow is defined in Pascal as follows:
PROCEDURE MoveWindow (theWindow:WindowPtr; hGlobal,vGlobal:INTEGER; front:BOOLEAN);
To call this ROM routine, you must match the parameters to the expected type. It is important to note that in Pascal, all parameters are passed by value unless they are preceded by VAR, in which case they are passed by reference.
To call MoveWindow, you need to pass a pointer to the window that you want to move, two integer values for the horizontal and vertical distance to which you want the window to move, and a boolean value for determining if the window is in the foreground or background. Because BASIC passes parameters by reference, you must put parentheses around the variable to pass it by value. The correct syntax to call MoveWindow from QuickBASIC is as follows:
The "PQ" is the call type. The "P" means the call is to a stack-based procedure with no return value, and the "Q" allows calls to be made to routines that are not listed in the resource. A complete description of all of the call types can be found on Page 499 of the "QuickBASIC for Macintosh: Language Reference" manual.
The second parameter, &HA91b, is the ROM trap number. These trap numbers can be found in Appendix C of Volume III of "Inside Macintosh."
The third parameter (Winptr&) is a pointer to a window that you have created. Because this variable contains the pointer value (address) of the beginning of the window, you need to pass it by value, which is what the ROM routine is expecting. To pass the variable by value, enclose the variable in parentheses.
The fourth, fifth, and sixth parameters must also be passed by value; therefore, they must also be enclosed in parentheses.
The following is a complete QuickBASIC program that opens a window and then moves it after you press a key:
Toolbox "i" WINDOW 2, "test window",(10,40) - (250,200),1 w2& = 0 GetWindow w2& 'returns a pointer of the current window vglobal% = 150 hglobal% = 300 front% = -1 '-1 for true PRINT "Hit any key to move window" WHILE INKEY$ ="":WEND Toolbox "PQ",&HA91B,(w2&),(hglobal%),(vglobal%),(front%) WHILE INKEY$ = "":WEND
Additional query words: MQuickB