I would like to update my work on this, and the results.
First, consider this piece of code where I use PrnSel() to provide the option to PRINT, View, or Cancel ( a very familiar popup to all of us ), and under Print, there are two radio buttons which select either use the default printer, or select an Alternate printer. Then I create the PRINT object with the second statement.
- Code: Select all Expand view RUN
// Present the print selection option window and find the type
nPrnOpt := PRNSEL( aPrnTyp )
IF nPrnOpt = 0 // If Exit is specified, leave the print report function
RETURN NIL
ENDIF
// Now tell the print engine the type of format to use. This also creates teh oPrnWO object
IF nPrnOpt = 1
PRINT oPrnWO NAME "Workorder Printing" TO cUsePrint PREVIEW FROM USER MODAL // Preview with alternate printer selection
ELSEIF nPrnOpt = 2
PRINT oPrnWO NAME "Workorder Printing" TO cUsePrint PREVIEW MODAL // Preview with default printer
ELSEIF nPrnOpt = 3
PRINT oPrnWO NAME "Workorder Printing" TO cUsePrint FROM USER // Send to user selected printer
ELSEIF nPrnOpt = 4
PRINT oPrnWO NAME "Workorder Printing" TO cUsePrint // Send to default printer
ENDIF
Here is the PrnSel( ) function code:
- Code: Select all Expand view RUN
FUNCTION prnsel
// Declare EXTERNAL variables
LOCAL ofBrush
MEMVAR oWnd, lGxPrsnt
// Declare LOCAL variables
LOCAL prnmeth := 0, oDlg, oRadOpt, lView := .F. , lPrint := .F. , nPrn := 1
LOCAL cTitle := "Printer Selection Options"
lGxPrsnt := .T. // Assign static values
// Create the dialog
IF cWSshow = "W"
DEFINE DIALOG oDlg RESOURCE "PRNSELw" BRUSH oBrush TITLE cTitle TRANSPARENT
ELSE
DEFINE DIALOG oDlg RESOURCE "PRNSEL" BRUSH oBrush TITLE cTitle TRANSPARENT
ENDIF
// Create the radio control
REDEFINE RADIO oRadOpt VAR nPrn ID 353, 354 OF oDlg ON CHANGE oRadOpt:Refresh() // Option 1 is using the default printer, 2 is to select an alternate printer, and translates to the FROM USER command when creating the object
// Create the button controls
REDEFINE BTNBMP ID 350 of oDlg RESOURCE "HRZMIN" PROMPT "View" NOBORDER TRANSPARENT ;
ACTION ( lView := .T., oDlg:End ) MESSAGE "Preview the report, with an option to print"
REDEFINE BTNBMP ID 351 of oDlg RESOURCE "HRPRINT" PROMPT "Print" NOBORDER TRANSPARENT;
ACTION ( lPrint := .T., oDlg:End ) MESSAGE "Print the report without previewing"
REDEFINE BTNBMP ID 352 of oDlg RESOURCE "HREXIT" PROMPT "Cancel" NOBORDER TRANSPARENT;
ACTION ( oDlg:End ) MESSAGE "Cancel the print operation "
// Activate the dialog
ACTIVATE DIALOG oDlg CENTERED
IF lView .AND. nPrn = 2 // View and select printer
prnmeth := 1
ELSEIF lView .AND. nPrn = 1 // View and default printer
prnmeth := 2
ELSEIF lPrint .AND. nPrn = 2 // Print with selection
prnmeth := 3
ELSEIF lPrint .AND. nPrn = 1 // Print to default
prnmeth := 4
ENDIF
RETURN ( prnmeth )
This works fine. The area of concern is nPrnOpt = 3. In the FWH PRINT class, this pops up the Windows option for selecting the printer to use. It has worked fine, and continues to work in all other print routines.
Now, I wanted to have the ability to specify a printer to which the program will default when printing the Invoice document. If I modify the
output within the print object, there is no selection capability. Those options occur when creating the object itself. So, I decided to change the default printer early in the .prg,, before the jobject is created, and stay with the above code. I use the following:
- Code: Select all Expand view RUN
// Obtain old printer
cOldPrinter := WIN_PRINTERGETDEFAULT( )
// Set to default printer
WIN_PRINTERSETDEFAULT( cUsePrint )
cUsePrint is a valid printer name string.
Now, the program will automatically print to the new default printer if I choose the Print button from PRNSEL(), and when in View mode ( rPreview ), it will also allow me to select a different printer. HOWEVER, if I choose Alternate Printer in the PrnSel() function, it does not give me the popup printer dialog, but simply sends it to the default I have provided.
I've looked at the source code for the printer class, but can't seem to find a reason for why this is occuring.
I feel I'm so close to the proper solution, but being blocked for some unknown reason.
Tim