Previous Topic Next topic Print topic


PC_PRINTER_SET_DEFAULT

Sets a process-wide default printer before a printer is opened.

Syntax:

call "PC_PRINTER_SET_DEFAULT" using by value default-option
                              by reference   default-struct
                              returning      status-code

Parameters

default-option
Call prototype (see Key): cblt-x4-comp5
Picture: pic x(4) comp-5.
default-struct
Group predefined as cblt-printer-default containing:
01 cblt-printer-default                typedef.
  03 cblte-pd-printer-name.
    05 cblte-pd-printer-name-length    cblt-x2-comp5.	*> pic x(4) comp-5.
    05 cblte-pd-printer-name           cblt-x1.       *> Occurs depending on
                                                      *> cblte-pd-printer-name-length.
                                                      *> pic x (printer name length)
  03 cblte-pd-printer-browse REDEFINES cblte-pd-printer-name.
    05 cblte-pd-printer-browse-hwnd    cblt-HWND.
    05 cblte-pd-printer-browse-namelen cblt-x2-comp5. *> pic x(4) comp-5.
    05 cblte-pd-reserved               cblt-x2-comp5. *> pic x(4) comp-5.
    05 cblte-pd-printer-browse-name    cblt-x1.       *> Occurs depending on
                                                      *> cblte-pd-printer-browse-namelen.
                                                      *> pic x (printer name length)
status-code
See Library Routines - Key.

On Entry:

default-option
Specifies the default option:
1 Sets the default printer to be used
2 Browses for a default printer.
Whendefault-option is set to 1:
printer-name-length
The length of the printer-name
printer-name
The name of the printer
Whendefault-option is set to 2:
browser-hwnd
The handle for the printer browser

On Exit:

When default-option is set to 2:
printer-name-length
The length of the printer-name
printer-name
The name of the printer
reserved
Reserved.
status-code
Printer Handling Routines Return Codes

Comments:

If you set default-option to 2, this function returns the user-selected printer but does not set it as the default printer.

The printer name must be entered as UNC format (that is, the device's full name as it appears on the network).

Examples:

Example 1:

The following example shows how to use PC_PRINTER_SET_DEFAULT to set the default printer.

 working-storage section.
 01 MyDocumentInfo.
   03 filename.
     05 len              pic x(2) comp-5.
     05 body             pic x(128).
   03 document.
     05 len              pic x(2) comp-5.
     05 body             pic x(128).
   03 document-flags     pic x(4) comp-5.
   03 window-hwnd        pic x(4) comp-5.
 01 Printer-RetCode pic  9(4) comp-5.

 78 USE-OPEN-DIALOG      value 1.
 78 USE-FONT-DIALOG      value 2.
 78 USE-FORCE-PORTRAIT   value 4.
 78 USE-FORCE-LANDSCAPE  value 8.
 78 USE-PROGRESS-DIALOG  value 16.

 01 default-info.
   03 option             pic x(4) comp-5.
   03 ourprinter.
     05 len              pic x(2) comp-5.
     05 body             pic x(128).

 78 SET-DEFAULT-PRINTER  value h"0001".
 procedure division.

     move "My Color PS" 
       to body of ourprinter of default-info
     move 11 to len of ourprinter of default-info
     move SET-DEFAULT-PRINTER to option of default-info

     call "PC_PRINTER_SET_DEFAULT" using 
                     by value option of default-info,
                     by reference ourprinter of default-info
           returning Printer-RetCode
     end-call

     if Printer-RetCode not equal zero
         display "Unable to setup a default printer"
         display " + Retcode = " Printer-RetCode
         stop run
     end-if

     move "c:\config.sys" to body of filename
     move 13 to len of filename
 
     move "My Config.sys" to body of document
     move 13 to len of document

     move USE-PROGRESS-DIALOG to document-flags
     move zero to window-hwnd

     call "PC_PRINT_FILE" using by reference filename
                                by reference document
                                by value document-flags
                                by value window-hwnd
                                returning Printer-RetCode
     end-call

     if Printer-RetCode not equal zero
         display "PC_PRINT_FILE failed.. " Printer-RetCode
     else
         display "PC_PRINT_FILE: OK"
     end-if
     .

Example 2:

The following example shows how to use PC_PRINTER_SET_DEFAULT to browse for a printer.

 working-storage section.
 01 MyDocumentInfo.
   03 filename.
     05 len                 pic x(2) comp-5.
     05 body                pic x(128).
   03 document.
     05 len                 pic x(2) comp-5.
     05 body                pic x(128).
   03 document-flags        pic x(4) comp-5.
   03 window-handle         pic x(4) comp-5.

 01 MyDefaultPrinter.
   03 hwnd                  pic x(4) comp-5.
   03 len                   pic x(2) comp-5.
   03 reserved              pic x(2) comp-5.
   03 body                  pic x(128).

 01 Printer-RetCode         pic 9(4) comp-5.

 78 USE-OPEN-DIALOG         value 1.
 78 USE-FONT-DIALOG         value 2.
 78 USE-FORCE-PORTRAIT      value 4.
 78 USE-FORCE-LANDSCAPE     value 8.
 78 USE-PROGRESS-DIALOG     value 16.

 01 default-info.
   03 option                pic x(4) comp-5.
   03 ourprinter.
     05 len                 pic x(2) comp-5.
     05 body                pic x(128).

 78 SET-DEFAULT-PRINTER     value h"0001".
 78 BROWSE-DEFAULT-PRINTER  value h"0002".

 linkage section.
 01 lnk-hwnd                 pic x(4) comp-5.

 procedure division using by value lnk-hwnd.
     move BROWSE-DEFAULT-PRINTER to option of default-info
     move lnk-hwnd to hwnd of MyDefaultPrinter
     move 127 to len of MyDefaultPrinter

     call "PC_PRINTER_SET_DEFAULT" using
                             by value option of default-info
                             by reference hwnd
                   returning Printer-RetCode
     end-call

     if Printer-RetCode not equal zero
         display "Unable to browse for a default printer"
         display " + Retcode = " Printer-RetCode
         stop run
     end-if

     display "Browse Printer : "
         body of MyDefaultPrinter(1:len of MyDefaultPrinter)

     move SET-DEFAULT-PRINTER to option of default-info
     move len of MyDefaultPrinter to len of ourprinter
     move body of MyDefaultPrinter(1:len of MyDefaultPrinter)
         to body of ourprinter

     call "PC_PRINTER_SET_DEFAULT" using
                     by value option of default-info
                     by reference ourprinter of default-info
                     returning Printer-RetCode
     end-call

     if Printer-RetCode not equal zero
         display "Unable to set a default printer"
         display " + Retcode = " Printer-RetCode
         stop run
     end-if

     move "c:\config.sys" to body of filename
     move 13 to len of filename
 
     move "My Config.sys" to body of document
     move 13 to len of document

     move USE-PROGRESS-DIALOG to document-flags
     move zero to window-handle

     call "PC_PRINT_FILE" using by reference filename
                                by reference document
                                by value document-flags
                                by value window-handle
                          returning Printer-RetCode
     end-call

     if Printer-RetCode not equal zero
         display "PC_PRINT_FILE failed.. " Printer-RetCode
     else
         display "PC_PRINT_FILE: OK"
     end-if
     .
Previous Topic Next topic Print topic