Selecting a printer

In this section:

Using a standard call-back function

In most Windows applications, such as Word for Windows, a standard printer dialog box is produced in response to a user button press or menu activation. Several ClearWin+ standard call-back functions are supplied to perform this task, each of which takes another call-back as an additional argument. The standard printer dialog is automatically displayed and the call-back will contain your code to write or draw to the printer. This call-back will only be called if the user selects a printer from the dialog (as opposed to pressing the Cancel button).

PRINTER_OPEN

Takes an integer Fortran unit number and another
callback function as arguments. Displays a dialog box
to select the printer and connects it to the given
Fortran unit number.

PRINTER_OPEN1

This also takes a Fortran unit number and another
call-back function as arguments. It uses the printer
previously selected using PRINTER_OPEN.

HTML_PRINTER_OPEN

This takes a Fortran unit number and another call-
back function. It displays a dialog box to select the
printer and connects it to the given Fortran unit
number.

HTML_PRINTER_OPEN1

This also takes a Fortran unit number and another
call-back function. It uses the previously selected
printer.

GPRINTER_OPEN

This takes another call-back as argument and displays
a dialog box to select the printer. The printer is
connected as the current drawing surface for the
duration of the call-back, which should perform the
required graphics operations.

GPRINTER_OPEN1

This operates in the same way as GPRINTER_OPEN,
except that a previously opened printer is used.


For example, here is a program that will respond to the button press by prompting the user for a printer and printing 'Hello'.

  EXTERNAL printer
  i=winio@('Press this button to print a page: ')
  i=winio@('%^bt[Print]&','PRINTER_OPEN',7,printer)
  i=winio@('%2nl%cn%bt[OK]')
  END
c-----
  INTEGER FUNCTION printer()
  WRITE(7,*)'Hello'
  CLOSE(7)
  printer=2
  END

Notice that the unit is closed before the call-back function exits. Typically, the call-back function should return a value of 2 to indicate that the associated window should stay open without a screen update. However, other call-back return values may be used as described in Clearwin+ call-back functions.

Using the HTML_PRINTER_OPEN or HTML_PRINTER_OPEN1 standard call-backs it is easy to generate pleasantly formatted text output to the printer. This mechanism uses the same subset of HTML as that used by %ht (Hypertext) except that one mark-up <PB> is added to set a page break. Here is a simple example:

      WINAPP
      INTEGER i,winio@
      EXTERNAL test
      i=winio@('%sc','HTML_PRINTER_OPEN',7,test)
      END
c---
      INTEGER FUNCTION test()
      WRITE(7,'(a)')'<h1>The output</h1>'
      WRITE(7,'(a)')'This is <i>Italic</i>.<p>'
      WRITE(7,'(a)')'And this is <b>Bold</b>.<p>'
      CLOSE(7)
      test=2
      END

The standard call-backs GPRINTER_OPEN and GPRINTER_OPEN1 do not connect the printer to a Fortran unit number, but rather they create a drawing surface that becomes the current drawing surface. The call-back that is an additional argument to these standard call-backs is used to draw to this surface. The current drawing surface reverts to the previous surface (if any) at the end of the call-back. An example is given in Printer graphics.

 

Using OPEN_PRINTER@ etc. to create a drawing surface

Alternatively, you can use explicit function calls to create a drawing surface and to attach it to a printer for graphics drawing:

OPEN_PRINTER@ 

Displays the standard printer dialog to enable graphics output to be sent to a printer.

OPEN_PRINTER1@ 

Re-opens a graphics printer using settings from a previous call to OPEN_PRINTER@.

OPEN_PRINTER_TO_FILE@ 

Displays the standard printer dialog to enable graphics output to be sent to a file.

OPEN_PRINTER1_TO_FILE@ 

Sends graphics output to a file supplied as an argument.

PRINT_GRAPHICS@ 

Manages calls to OPEN_PRINTER@ and CLOSE_PRINTER@. A supplied callback is used to print the graphics


Each of these functions returns zero if the user cancels the operation, and each takes a user identifier as input that is used to switch between drawing surfaces using SELECT_GRAPHICS_OBJECT@. An example is given in Using a metafile to print multiple copies.

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited