How to Dump Current Macintosh Screen or Window to Printer (32972)
The information in this article applies to:
- Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0
- Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0a
- Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0b
This article was previously published under Q32972 SUMMARY
This article describes how a QuickBasic program can dump the entire
Macintosh screen (Code Example 1) or dump just the current window
contents (Code Example 2) to an Apple ImageWriter or LaserWriter
printer.
When the examples below print color screens, the pixel colors are
translated as follows:
White <= yellow, magenta, cyan, white
Black <= red, green, blue, black
For more information about color translation of the GET and PUT
statements, query on the following words in the Microsoft Knowledge
Base:
graphics and get and put and monochrome and macintosh
MORE INFORMATION
Both examples 1 and 2 require dynamic arrays; therefore, if you
compile, you must compile WITHOUT the "Make All Arrays STATIC" option
in QuickBasic. The interpreter in QuickBasic always uses dynamic
arrays.
Code Example 1
The PrintScreen subprogram in the Utility Subprograms file in the "QB
Demos" folder is very similar to the following example, and can be
used in place of this example to save retyping.
The QuickBasic subprogram below enables you to dump the entire current
Macintosh screen contents to the printer. Unlike the LCOPY statement,
which also performs a screen dump, this subprogram also works for
color screens and LaserWriters, although LaserWriter output will take
a very long time. (LCOPY works only with a directly connected Apple
ImageWriter and does not work over the AppleTalk network or to an
Apple LaserWriter.)
PrintScreen 0,0,0 ' Prints whole screen without any scaling.
END
SUB PrintScreen(scale%,x%,y%) STATIC
' If scale% is true (nonzero) then the output is scaled to x% wide and
' y% high. If scale% is false (zero) then the screen is printed full
' size, and x% and y% are ignored.
' Calculate array size:
max&=(4+(SYSTEM(6)+1)*2*INT((SYSTEM(5)+16)/16))/8+1
' Make sure there's enough memory and the array is within bounds.
' BEEP and EXIT if screen too big:
IF FRE(0)<max&*8+26 OR max&>32767 THEN BEEP :EXIT SUB
DIM origin%(1),screen#(max&)
' Get relative offset from current window(0,0):
LocaltoGlobal origin%(0)
x2 = SYSTEM(5)-origin%(1)
y2 = SYSTEM(6)-origin%(0)
GET (-origin%(1),-origin%(0))-(x2,y2),screen#
OPEN "lpt1:prompt" FOR OUTPUT AS #10
WINDOW OUTPUT #10
IF scale% THEN PUT(0,0)-(x%,y%),screen# ELSE PUT(0,0),screen#
CLOSE #10
ERASE origin%,screen#
END SUB
Code Example 2
The following example sends just the contents of the current window to
the printer:
FOR J=1 TO 10 : PRINT "This goes to printer" : NEXT
' Calling this SUBprogram prints just the contents of the current
' window:
CALL PrintWindow
END
SUB PrintWindow STATIC
max&=FRE(-1) ' Compacts memory to avoid heap memory fragmentation
' Calculate array size:
wh=WINDOW(3)-1 ' Window height minus one pixel of border.
ww=WINDOW(2)-1 ' Window width minus one pixel of border.
max&=(4+(wh+1)*2*INT((ww+16)/16))/4 + 1
' Make sure there's enough memory and the array is within bounds.
' BEEP and EXIT if window image is too big:
IF max&*4+26>FRE(0) OR max&>32767 THEN BEEP :EXIT SUB
DIM win&(max&)
GET (0,0)-(ww,wh),win& ' GET current window contents into array.
max&=FRE(-1) ' Compacts memory before OPENing printer device name
OPEN "lpt1:prompt" FOR OUTPUT AS #10
WINDOW OUTPUT #10
PUT(0,0),win& ' PUT image to printer.
CLOSE #10
ERASE win&
END SUB
Modification Type: | Major | Last Reviewed: | 10/20/2003 |
---|
Keywords: | KB32972 |
---|
|