Microsoft KB Archive/49753

= LocalToGlobal/GlobalToLocal Convert Window/Screen Coordinates =

Article ID: 49753

Article Last Modified on 1/8/2003

-

APPLIES TO


 * Microsoft QuickBasic Compiler for Macintosh 1.0

-



This article was previously published under Q49753



SUMMARY
This article gives examples of how to use LocalToGlobal and GlobalToLocal, which are Microsoft BASIC Library Code (MBLC) routines built into Microsoft QuickBASIC Version 1.00 for the Apple Macintosh.

LocalToGlobal and GlobalToLocal are useful to coordinate graphics statements that use screen coordinates with those that use window coordinates.

LocalToGlobal takes a point, measured in y and x coordinates in pixels relative to the current output window, and returns its current coordinates relative to the Macintosh screen.

GlobalToLocal takes a point, measured in y and x coordinates in pixels relative to the Macintosh screen, and returns its current coordinates relative to the current output window.



MORE INFORMATION
On the Macintosh, a point at coordinates (0,0) is at the upper-left corner (of the screen or window). Pixels in the y direction are positive when below the upper-left corner. Pixels in the x direction are positive when to the right of the upper-left corner.

LocalToGlobal Example
The following program shows how the global screen coordinates of a fixed local window point change as the window is dragged: WINDOW 1,&quot;Move this window&quot;,(100,100)-(400,200),1 localx = 3           ' x coordinate relative to window localy = 30          ' y coordinate relative to window PRINT &quot;y=&quot;; localy; &quot;x=&quot;; localx; &quot; in window coordinates is...&quot; DIM p%(1)  ' First element of p% array is y coordinate, second is x. WHILE INKEY$ = &quot;&quot;     ' Loop until any key is pressed. p%(0) = localy     ' Reassign window y coordinate. p%(1) = localx     ' Reassign window x coordinate.

' LocalToGlobal converts localx,localy window coordinates to ' global (screen) coordinates: LocalToGlobal p%(0)

LOCATE 3,1 MOVETO localx,localy PRINT CHR$(165)   ' Prints a dot at position fixed within window. PRINT &quot;y=&quot;; p%(0); &quot;x=&quot;; p%(1); &quot; in screen coordinates     &quot; WEND WINDOW CLOSE 1

GlobalToLocal Example
The following program shows how the local window coordinates of a fixed global screen point change as the window is dragged: WINDOW 1,&quot;Move this window&quot;,(100,100)-(400,300),1 globalx = 250 globaly = 150 DIM p%(1) ' First element of p% array is y coordinate, second is x. PRINT &quot;y=&quot;; globaly; &quot;x=&quot;; globalx; &quot; in global coordinates is...&quot; WHILE INKEY$=&quot;&quot;   ' Loop until any key is pressed. p%(0) = globaly  ' Reassign fixed global y coordinate p%(1) = globalx  ' Reassign fixed global x coordinate

' GlobalToLocal converts global screen coordinates to ' local x, local y coordinates for the current output window: GlobalToLocal p%(0)

LOCATE 2,1 PRINT &quot;y=&quot;; p%(0); &quot;x=&quot;; p%(1)&quot; in window coordinates    &quot; ' The following PRINTs a big dot (extended-ASCII character 165) ' at screen coordinates globalx,globaly. If you put one finger on ' the dot, and drag the window around with the other hand, you will ' see that the dot is drawn at the same screen position but at ' different coordinates relative to WINDOW 1. MOVETO p%(1),p%(0)  ' Move pen to local window coordinates. PRINT CHR$(165); WEND WINDOW CLOSE 1

Additional query words: MQuickB

Keywords: KB49753

-

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

© Microsoft Corporation. All rights reserved.