Microsoft KB Archive/32971

= How to Send Contents of a Specified Window to a Printer =

Article ID: 32971

Article Last Modified on 11/21/2006



This article was previously published under Q32971



SUMMARY
The following subprogram can be used to print a copy of a specified window to the printer. This example requires all arrays to be dynamic; therefore the Make All Arrays STATIC compile option cannot be used. The following PrintWindow subprogram can be found on the QuickBASIC distribution disks in the Utility Subprograms file in the QB Demos folder.



MORE INFORMATION
The program below does the following:


 * 1) Uses the WINDOW function to determine the coordinates of the current window
 * 2) Executes a graphics GET statement to get the whole window into an array
 * 3) OPENs the &quot;LPT1:PROMPT&quot; printer device as #10
 * 4) Executes the WINDOW OUTPUT #10 statement to redirect screen output to the printer
 * 5) Executes a graphics PUT statement using the array obtained in step 2

The following is the code example: 'The following statement makes a window that fills the screen: WINDOW 1,&quot;Maximum-Sized Window&quot;,(0,21)-(SYSTEM(5),SYSTEM(6)),3 FOR J=1 TO 18 : PRINT &quot;THIS IS ON THE WINDOW&quot; : NEXT PrintWindow 1,3 END SUB PrintWindow (n%,type%) STATIC ' n% = window id number. ' type% = window type. ' If 1 < type% < 7, then the window frame and contents are printed; ' otherwise only the window contents are printed. Window types can be ' from -7 through 7. max&=(4+(WINDOW(2)+21)*2*INT((WINDOW(3)+36)/16))/4+1 IF max&>32767 OR max&*4+26>FRE(0) THEN BEEP: EXIT SUB DIM win&(max&) saved%=WINDOW(0): WINDOW n%   l% = -1: t% = -1: b% = WINDOW(3)+1: r%=WINDOW(2)+1 SELECT CASE type% CASE 1,7   :t%=t%-18 :r%=r%+15 CASE 2     :t%=t%-7  :l%=-8 :b%=b%+6 :r%=r%+6 CASE 3     :b%=b%-1  :r%=r%-1 CASE 4     :b%=b%+1  :r%=r%+1 CASE 5     :t%=t%-18 CASE 6     :t%=t%-18 :b%=b%-1 :r%=r%-1 CASE ELSE  :t%=0 :l%=0 :b%=WINDOW(3)-1 :r%=WINDOW(2)-1 END SELECT GET (l%,t%)-(r%,b%),win& OPEN &quot;lpt1:prompt&quot; FOR OUTPUT AS #10 WINDOW OUTPUT #10 PUT (0,0),win& CLOSE #10 ERASE win& WINDOW saved% END SUB

Additional query words: MQuickB

Keywords: KB32971

-

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

© Microsoft Corporation. All rights reserved.