Printer Browser

I was looking at the examples in "PC_PRINTER_SET_DEFAULT". Example #2 uses the routine to brows for a printer. It then uses the routine to set the printer as the default. It then uses "PC_PRINT_FILE" to print a file to the printer. This is just what I need. The problem is that the example and the routine definition do not explain where the "Printer Browser Handle" comes from. The example uses a linkage section variable. Could you let me know where this handle comes from and how to use it? What I want to do is to let the user select a printer and then print two files to this printer. Concatenating the two files before printing is NOT an option. 

Parents
  • Verified Answer

    Hi Jerry,

    Sorry, the example is misleading.

    The browser handle is actually referring to the window handle that you would like to be the parent of the print selection dialog.

    You can set this to 0 is you want the current window to be the parent.

    I did a test here using the example in the docs and although it works fine from a native code project it does not appear to be working correctly from a managed code project.

    I will create an rpi for this.

    As a workaround in a managed code project you can use the PrintDialog class to get the printer name and use it instead of the browse function.

    Example:

              declare myprintdialog as type PrintDialog = new PrintDialog
              if myprintdialog::ShowDialog = type DialogResult::OK
                 move myprintDialog::PrinterSettings::PrinterName to body of ourprinter
                 move myprintDialog::PrinterSettings::PrinterName::Length to len of ourprinter
              end-if
           
               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 set a default printer"
                  display "   Retcode = " Printer-RetCode
                  stop run
               end-if
    
               move "c:\temp\mytest.txt" to body of filename
               move 18 to len of filename
     
               move "My test" to body of document
               move 7 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
               goback.
               
    
Reply
  • Verified Answer

    Hi Jerry,

    Sorry, the example is misleading.

    The browser handle is actually referring to the window handle that you would like to be the parent of the print selection dialog.

    You can set this to 0 is you want the current window to be the parent.

    I did a test here using the example in the docs and although it works fine from a native code project it does not appear to be working correctly from a managed code project.

    I will create an rpi for this.

    As a workaround in a managed code project you can use the PrintDialog class to get the printer name and use it instead of the browse function.

    Example:

              declare myprintdialog as type PrintDialog = new PrintDialog
              if myprintdialog::ShowDialog = type DialogResult::OK
                 move myprintDialog::PrinterSettings::PrinterName to body of ourprinter
                 move myprintDialog::PrinterSettings::PrinterName::Length to len of ourprinter
              end-if
           
               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 set a default printer"
                  display "   Retcode = " Printer-RetCode
                  stop run
               end-if
    
               move "c:\temp\mytest.txt" to body of filename
               move 18 to len of filename
     
               move "My test" to body of document
               move 7 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
               goback.
               
    
Children
No Data