Microsoft KB Archive/39094

= Example TOOLBOX Routine for Moving a WINDOW; System Can Bomb =

Article ID: 39094

Article Last Modified on 11/21/2006



This article was previously published under Q39094



SUMMARY
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.



MORE INFORMATION
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 &quot;Inside Macintosh&quot; (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: TOOLBOX &quot;PQ&quot;,&HA91b,(Winptr&),(hglobal%),(vglobal%),(front%) The &quot;PQ&quot; is the call type. The &quot;P&quot; means the call is to a stack-based procedure with no return value, and the &quot;Q&quot; 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 &quot;QuickBASIC for Macintosh: Language Reference&quot; manual.

The second parameter, &HA91b, is the ROM trap number. These trap numbers can be found in Appendix C of Volume III of &quot;Inside Macintosh.&quot;

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 &quot;i&quot; WINDOW 2, &quot;test window&quot;,(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 &quot;Hit any key to move window&quot; WHILE INKEY$ =&quot;&quot;:WEND Toolbox &quot;PQ&quot;,&HA91B,(w2&),(hglobal%),(vglobal%),(front%) WHILE INKEY$ = &quot;&quot;:WEND

Additional query words: MQuickB

Keywords: KB39094

-

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

© Microsoft Corporation. All rights reserved.