Microsoft KB Archive/49753

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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,"Move this window",(100,100)-(400,200),1
localx = 3            ' x coordinate relative to window
localy = 30           ' y coordinate relative to window
PRINT "y="; localy; "x="; localx; " in window coordinates is..."
DIM p%(1)   ' First element of p% array is y coordinate, second is x.
WHILE INKEY$ = ""     ' 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 "y="; p%(0); "x="; p%(1); " in screen coordinates      "
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,"Move this window",(100,100)-(400,300),1
globalx = 250
globaly = 150
DIM p%(1)  ' First element of p% array is y coordinate, second is x.
PRINT "y="; globaly; "x="; globalx; " in global coordinates is..."
WHILE INKEY$=""    ' 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 "y="; p%(0); "x="; p%(1)" in window coordinates     "
  ' 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