In this section:
Here is a simple program that uses the standard call-back GPRINTER_OPEN to respond to a button press and draws a diagonal line across the entire page. GPRINTER_OPEN creates a drawing surface and an additional call-back argument is used to contain code to draw to this surface.
WINAPP
INTEGER i,winio@
EXTERNAL test
i=winio@('%^bt[Open]','GPRINTER_OPEN',test)
END
c---
INTEGER FUNCTION test()
INCLUDE <windows.ins>
INTEGER xmax,ymax
CALL get_graphical_resolution@(xmax,ymax)
CALL draw_line_between@(0,0,xmax-1,ymax-1,15)
test=2
END
Notice that the call to GET_GRAPHICAL_RESOLUTION@ will work for all types of drawing surfaces. This means that the same code can be used to generate graphics output to the screen and to the printer.
Notice also that by default the drawing surface for the printer uses VGA rather than RGB mode. So in this example, the colour for DRAW_LINE_BETWEEN@ is provided as a colour index (15 represents intense white in this program) rather than an RGB value. Normally RGB mode is preferred and this requires a prior call of USE_RGB_COLOURS@(0,.true.) (see the example in Using a metafile to print multiple copies).
By using open_printer@ etc., it is possible to have two drawing surfaces, one attached to the screen and the other to a graphics printer or plotter. In the following example one identifier is attached to a %gr (Graphics Region) region (a screen drawing surface) whilst a second identifier is attached to a graphics printer drawing surface.
INTEGER ctrl,hnd1,hnd2
DATA hnd1,hnd2/1,2/
i=winio@('%`gr&',400L,300L,hnd1)
i=winio@('%ww%lw',ctrl)
j=select_graphics_object@(hnd1)
CALL draw_line_between@(100,100,300,200,15)
k=open_printer@(hnd2)
j=select_graphics_object@(hnd2)
CALL draw_filled_ellipse@(200,150,75,50,2)
k=close_printer@(hnd2)
As usual, open_printer@ generates a standard "Open Printer" dialog box from which the user selects a graphics printer or plotter. Subsequent calls to ClearWin+ drawing routines are written to this drawing surface and the output is generated when the ClearWin+ routine CLOSE_PRINTER@ or the routine NEW_PAGE@ is called.
Notes:
• OPEN_PRINTER@ etc. may be used independently of winio@.
• In the above example, j and k can be used to test for the success of the associated function calls.
• Printer surfaces will use GDI+ features if they are turned on.
• PRINT_GRAPHICS@ will help manage printing.