PRINT class printer options
PRINT class printer options
Perhaps someone has had a similar need and found a solution. Let me explain.
My client's computer defaults to Printer A. However, he wants his invoices to go to Printer B with its special paper.
Using the PRINT class, we have 3 options. We can send output directly to the default ( printer A ), select an Alternate printer ( ie. B, C, or D ), or View, and there select the default or alternate printer.
Once the print object is changed, if invoices always go to printer B, we can set the cModel to that printer, and it will go there by default.
For most people this works fine. They setup a default for invoices to go to printer B, and it's all automatic.
HOWEVER, my client wants this, but sometimes he wants to select an alternate printer. Unfortunately, if I specify a printer B as the output when creating the class object, it will not allow the dialogs to switch to any other printer.
The need here would be to set the default printer to the alternate ( B ) BEFORE creating the print class, then back after the invoice completes printing. This would trick the class to think B is the default and still allow a different printer to be selected. We just don't have a FWH or Harbour command that allows us to do this. Also, I'm not positive even that would work.
Any ideas would be appreciated.
Tim
My client's computer defaults to Printer A. However, he wants his invoices to go to Printer B with its special paper.
Using the PRINT class, we have 3 options. We can send output directly to the default ( printer A ), select an Alternate printer ( ie. B, C, or D ), or View, and there select the default or alternate printer.
Once the print object is changed, if invoices always go to printer B, we can set the cModel to that printer, and it will go there by default.
For most people this works fine. They setup a default for invoices to go to printer B, and it's all automatic.
HOWEVER, my client wants this, but sometimes he wants to select an alternate printer. Unfortunately, if I specify a printer B as the output when creating the class object, it will not allow the dialogs to switch to any other printer.
The need here would be to set the default printer to the alternate ( B ) BEFORE creating the print class, then back after the invoice completes printing. This would trick the class to think B is the default and still allow a different printer to be selected. We just don't have a FWH or Harbour command that allows us to do this. Also, I'm not positive even that would work.
Any ideas would be appreciated.
Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
- Antonio Linares
- Site Admin
- Posts: 42258
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: PRINT class printer options
Dear Tim,
As I commented you by email, you may use Windows API SetDefaultPrinter()
https://learn.microsoft.com/en-us/windo ... ultprinter
As I commented you by email, you may use Windows API SetDefaultPrinter()
https://learn.microsoft.com/en-us/windo ... ultprinter
Code: Select all | Expand
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
HB_FUNC( SETDEFAULTPRINTER )
{
hb_retl( SetDefaultPrinter( hb_parc( 1 ) ) );
}
#pragma ENDDUMP
- Antonio Linares
- Site Admin
- Posts: 42258
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: PRINT class printer options
Harbour provides it as function WIN_PRINTERSETDEFAULT( cPrinterName )
Re: PRINT class printer options
Look, pls:
Regards, saludos.
Code: Select all | Expand
// http://fivewin.com.br/index.php?/topic/27487-uso-do-getprintdc/
#include "FiveWin.ch"
#include "Objects.ch"
#define RGB_BLACK RGB( 0, 0, 0 )
#define RGB_RED RGB( 255, 0, 0 )
#define RGB_GREEN RGB( 0,255, 0 )
#define RGB_BLUE RGB( 0, 0,255 )
#define RGB_CYAN RGB( 0,255,255 )
#define RGB_YELLOW RGB( 255,255, 0 )
#define RGB_MAGENTA RGB( 255, 0,255 )
#define RGB_WHITE RGB( 255,255,255 )
#define FW_DONTCARE 0
#define FW_THIN 100
#define FW_EXTRALIGHT 200
#define FW_LIGHT 300
#define FW_NORMAL 400
#define FW_MEDIUM 500
#define FW_SEMIBOLD 600
#define FW_BOLD 700
#define FW_EXTRABOLD 800
#define FW_HEAVY 900
#define DMPAPER_A4 9
FUNCTION Main()
LOCAL oPrn, oPrint, oFnt, cPrinter := ""
LOCAL oDlg, oBrw
LOCAL aPrn := {}
LOCAL cDef, i := 1
// GetPrinters() and GetDefaultPrinter() do not work in Harbour
#ifdef __HARBOUR__
aPrn := aGetPrinters ()
cDef := DefaultPrinter()
#else // Harbour
aPrn := GetPrinters ()
cDef := GetDefaultPrinter()
#endif
IF Empty ( aPrn )
MsgAlert ( "No Printers found" )
RETURN NIL
ENDIF
DEFINE DIALOG oDlg FROM 2, 2 TO 21, 50 TITLE "Available Printers"
@ 1, 2 LISTBOX oBrw FIELDS aPrn[ i ] ;
HEADERS "Printer Array" ;
FIELDSIZES 200 ;
OF oDlg SIZE 100, 100
oBrw:bGoTop = { || i := 1 }
oBrw:bGoBottom = { || i := Eval( oBrw:bLogicLen ) }
oBrw:bSkip = { | nWant, nOld | nOld := i, i += nWant, ;
i := Max( 1, Min( i, Eval( oBrw:bLogicLen ) ) ), ;
i - nOld }
oBrw:bLogicLen = { || Len( aPrn ) }
oBrw:cAlias = "Array" // Just put something
@ 7.8, 2 SAY "Default printer: " + cDef
@ 1, 20 BUTTON "&Print (FW)" OF oDlg ACTION TestCopias ( aPrn[i] )
@ 2, 20 BUTTON "&Print (xH)" OF oDlg ACTION Test2 ( aPrn[i] )
@ 3, 20 BUTTON "&End " OF oDlg ACTION( oDlg:End() )
ACTIVATE DIALOG oDlg CENTERED
RETURN NIL
FUNCTION TestCopias( cPrn ) // Imprimir varias copias
LOCAL nI, nCopias := 2
// SetCopies
FOR nI := 1 TO nCopias
TestPrint( cPrn )
NEXT
RETURN NIL
FUNCTION TestPrint( cPrn )
LOCAL oFnt, oPrint
LOCAL cText := "Este é um texto de teste para impressão"
PRINT oPrint NAME "Formulario" TO ( cPrn )
DEFINE FONT oFnt NAME "ARIAL" SIZE 0, - 14 OF oPrint
// oPrint:SetCopies ( 2 ) // No funciona
oPrint:SetLandscape()
// oPrint:Setup () // check the settings
PAGE
oPrint:CmSay ( 1, 1, cText, oFnt )
ENDPAGE
ENDPRINT
oFnt:End()
RETURN NIL
FUNCTION Test2 ( cPrn )
LOCAL oPrinter
LOCAL aFonts, cFont, nFont
oPrinter := Win32Prn():new( cPrn ) // Create printer object and configure print job
oPrinter:landscape := .F.
oPrinter:formType := DMPAPER_A4
oPrinter:copies := 2 // <--- 2 copies !!
IF ! oPrinter:create() // Create device context
Alert( "Cannot create device context" )
QUIT
ENDIF
IF ! oPrinter:startDoc( "xHarbour test page" ) // Create print job
Alert( "Cannot create document" )
QUIT
ENDIF
oPrinter:textOut( "Text in default font" ) // Text in fixed font
oPrinter:bold( FW_EXTRABOLD )
oPrinter:textOut( oPrinter:fontName )
oPrinter:bold( FW_NORMAL )
oPrinter:newLine()
aFonts := oPrinter:getFonts()
nFont := AScan( aFonts, ;
{|a| "ARIAL" $ Upper( a[1] ) } )
cFont := aFonts[nFont,1]
oPrinter:setFont( cFont ) // Text in proportional font
oPrinter:textOut( "Text in Arial font" )
oPrinter:bold( FW_EXTRABOLD )
oPrinter:textOut( oPrinter:fontName )
oPrinter:bold( FW_NORMAL )
oPrinter:newLine()
oPrinter:setColor( RGB_YELLOW, RGB_BLUE ) // Colored text
oPrinter:textOut( "Yellow on Blue" )
oPrinter:newLine()
oPrinter:setPen( PS_DASH, 5, RGB_GREEN ) // Draw colored line across page
oPrinter:line( oPrinter:posX, ;
oPrinter:posY, ;
oPrinter:rightMargin, ;
oPrinter:posY )
oPrinter:endDoc() // Send output to printer
oPrinter:destroy() // Release GDI device context
RETURN NIL
FUNCTION DefaultPrinter()
LOCAL nPrn, nRet, sGetDefaultPrinter
nRet := PrinterSetUp()
nPrn := PrnGetName()
IF( nRet # 0 )
SetDefaultPrinter( PRNGETNAME() )
sGetDefaultPrinter := GetDefaultPrinter()
// ? PrnStatus( sGetDefaultPrinter )
IF PrnStatus( sGetDefaultPrinter ) = 4096
// Verifica se SPOOLER esta desligado e tenta liga-lo
MsgRun( sGetDefaultPrinter + ": " + isprint( GetDefaultPrinter() ) + ;
" ou Spooler Desligado.", "Status da Impressora", ;
{|| WinExec( "NET START SPOOLER", 7 ) } )
ENDIF
//? GetPrinter()
ELSE
MsgAlert ( "No Printers found" )
RETURN( .F. )
ENDIF
RETURN( sGetDefaultPrinter )
// FIM
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Re: PRINT class printer options
Dear Tim,
maybe this helps?
Best regards,
Otto
maybe this helps?
Best regards,
Otto
Code: Select all | Expand
coldprinter := StandardDruckerUmstellen( cDruckerName )
REPORT oReport TITLE " ", cTITLE, " " LEFT ;
FONT oFont1,;
oFont2,;
oFont3 ;
PEN oPen1;
HEADER setup():LizenzNehmer()," ", ALLTRIM("Erstellt: " + dtoc(date())+ " - "+time()) RIGHT;
FOOTER "Seite " + Str(oReport:nPage,3) RIGHT PREVIEW
COLUMN TITLE "ZimmerNr" DATA TBuchung->ZimmerNr SIZE 5 FONT 2
COLUMN TITLE "erwachsene" DATA TBuchung->erwachsene TOTAL SIZE 9 PICTURE "999,999,999.99"
COLUMN TITLE "kinder" DATA TBuchung->kinder TOTAL SIZE 9 PICTURE "999,999,999.99"
COLUMN TITLE "planname" DATA TBuchung->planname SIZE 15
COLUMN TITLE "standard" DATA TBuchung->standard SIZE 15
COLUMN TITLE "markerfix" DATA TBuchung->markerfix SIZE 5
COLUMN TITLE "tisch" DATA TBuchung->tisch SIZE 15
END REPORT
oReport:CellView()
oLine:= oReport:oTitle
oLine:aFont[2] := {|| 3}
oReport:bInit := { || TBuchung->( DbGotop( ) ) } //activate ToExCel
ACTIVATE REPORT oReport
change2default_printer( coldprinter )
endif
Code: Select all | Expand
//coldprinter := StandardDruckerUmstellen( cDruckerName )
function StandardDruckerUmstellen( cDruckerName )
local coldprinter := prnGetName() // default printer
*----------------------------------------------------------
if len( ALLTRIM( cDruckerName ) ) > 0
WriteProfString( "windows", "device", cDruckerName ) // change to new printer
SetPrintDefault( cDruckerName )
PrinterInit()
SysRefresh()
endif
return( coldprinter )
//------------------------------------------------------------------------------------------//
function change2default_printer( coldprinter )
WriteProfString( "windows", "device",coldprinter) // default printer
SetPrintDefault(coldprinter)
PrinterInit()
SysRefresh()
return nil
//------------------------------------------------------------------------------------------//
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
Re: PRINT class printer options
Dear Tim,
... and I always check the the default printer.
Best regards,
Otto
... and I always check the the default printer.
Best regards,
Otto
Code: Select all | Expand
function checkprinters
local aComboPrn := GetAllEntrys()
local I := 0
local hPRN_STATUS := {=>}
local cStatus := ""
local aPRNCheck := {}
local oPrn
local lshowPrinters := .t.
local cdefaultPRN := ud_prngetname()
local cDefaultYesNO := ""
*----------------------------------------------------------
hPRN_STATUS["0" ] := "PRINTER_STATUS_OK"
hPRN_STATUS["1" ] := "PRINTER_STATUS_PAUSED"
hPRN_STATUS["2" ] := "PRINTER_STATUS_ERROR"
hPRN_STATUS["4" ] := "PRINTER_STATUS_PENDING_DELETION"
hPRN_STATUS["8" ] := "PRINTER_STATUS_PAPER_JAM"
hPRN_STATUS["16" ] := "PRINTER_STATUS_PAPER_OUT"
hPRN_STATUS["32" ] := "PRINTER_STATUS_MANUAL_FEED"
hPRN_STATUS["64" ] := "PRINTER_STATUS_PAPER_PROBLEM"
hPRN_STATUS["128" ] := "PRINTER_STATUS_OFFLINE"
hPRN_STATUS["256" ] := "PRINTER_STATUS_IO_ACTIVE"
hPRN_STATUS["512" ] := "PRINTER_STATUS_BUSY"
hPRN_STATUS["1024" ] := "PRINTER_STATUS_PRINTING"
hPRN_STATUS["2048" ] := "PRINTER_STATUS_OUTPUT_BIN_FULL"
hPRN_STATUS["4096" ] := "PRINTER_STATUS_NOT_AVAILABLE"
hPRN_STATUS["8192" ] := "PRINTER_STATUS_WAITING"
hPRN_STATUS["16384" ] := "PRINTER_STATUS_PROCESSING"
hPRN_STATUS["32768" ] := "PRINTER_STATUS_INITIALIZING"
hPRN_STATUS["65536" ] := "PRINTER_STATUS_WARMING_UP"
hPRN_STATUS["131072" ] := "PRINTER_STATUS_TONER_LOW"
hPRN_STATUS["262144" ] := "PRINTER_STATUS_NO_TONER"
hPRN_STATUS["524288" ] := "PRINTER_STATUS_PAGE_PUNT"
hPRN_STATUS["1048576" ] := "PRINTER_STATUS_USER_INTERVENTION"
hPRN_STATUS["2097152" ] := "PRINTER_STATUS_OUT_OF_MEMORY"
hPRN_STATUS["4194304" ] := "PRINTER_STATUS_DOOR_OPEN"
hPRN_STATUS["8388608" ] := "PRINTER_STATUS_SERVER_UNKNOWN"
hPRN_STATUS["16777216" ] := "PRINTER_STATUS_POWER_SAVE"
if lshowPrinters = .t.
For I := 1 to len( aComboPrn )
if PrnStatus( aComboPrn[ I ] ) <> 0
// AADD( aPRNCheck, { aComboPrn[ I ], "Printer e r r o r " } )
endif
If len(alltrim(cdefaultPRN)) > 0
if aComboPrn[ I ] = cdefaultPRN
cDefaultYesNO := "default printer"
else
cDefaultYesNO := ""
endif
endif
cStatus := ALLTRIM ( STR( PrnStatus( aComboPrn[ I ] ) ) )
TRY
AADD( aPRNCheck, { aComboPrn[ I ], hPRN_STATUS[ cStatus] , cDefaultYesNO } )
CATCH
AADD( aPRNCheck, { aComboPrn[ I ], "Status nicht definiert " + cStatus , cDefaultYesNO} )
END
/*
? GetPrintDefault()
ChangeStandardPrinter( aComboPrn[ I ] )
? ud_prngetname()
Printersetup()
*/
NEXT
//xbrowse( aPRNCheck, "Printers installed - Status" )
ShowPrinters( aPRNCheck )
endif
If GetPrintDefault() = 0
//? "no default printer"
MetroMsgInfo( "Programmabbruch", "WINDOWS: There is no default printer currently selected" + CRLF +;
"Go into your Windows Control Panel and choose the Printer settings." + CRLF + CRLF +;
"Right-click the printer that you want to use, and then click Set as Default Printer."+ CRLF+;
"A check mark on the printer icon indicates that the printer is now the default printer." + CRLF + CRLF +;
"If the customer requires help with this they should refer to their IT administrator." )
else
//
? "Default printer " + ud_prngetname()
endif
return nil
//----------------------------------------------------------------------------//
FUNCTION GetAllEntrys() //show all printers
*----------------------------------------
local aDevices:={}, cAllEntries, cEntry, I, cName, cPrn, cPort, J
cAllEntries := STRTRAN( GetProfString( "Devices" ), Chr( 0 ), CRLF )
FOR I:= 1 TO MlCount( cAllEntries )
cName := MemoLine( cAllEntries,,I)
cEntry := GetProfString( "Devices",cName,"")
J := 2
DO WHILE ! EMPTY(cPort := StrToken(cEntry,J++,","))
*msginfo( TRIM(cName) ) +" , "+TRIM(cPort)
AADD(aDevices, TRIM( cName ))
ENDDO
NEXT
RETURN aDevices
//----------------------------------------------------------------------------//
function ChangeStandardPrinter( cPrintername )
local coldprinter := prnGetName() // default printer
*----------------------------------------------------------
if len( ALLTRIM( cPrintername ) ) > 0
WriteProfString( "windows", "device", cPrintername ) // change to new printer
SetPrintDefault( cPrintername )
PrinterInit()
SysRefresh()
endif
return( coldprinter )
//------------------------------------------------------------------------------------------//
function ud_PrnGetName()
local cret, oprn
PRINTER oPrn
cRet := oPrn:getmodel()
endprint
return cret
//------------------------------------------------------------------------------------------//
FUNCTION MetroMsgInfo( cTitel, cAnzeige1 )
local lVar := .f.
local oDlg, oGet, oBTNNaviWeiter, oBTNNaviInfo, obtnAbbruch, oCbx
local cPassword := Space( 10 )
local nWidth := GetSysMetrics( 0 )
local nHeight := GetSysMetrics( 1 )
local nLine := 0
local nRowSpace := 20
local nRowOffset := 20
local cInfo := ( procname(1) + " " + str( procline(1) ) )
local oFntMetroNormal2, oFntMetroMedium2,oFntMetroFLATBTN
local nRibbonTopClr := rgb(227, 162, 26)
*----------------------------------------------------------
DEFAULT cTitel := "Infobox"
*----------------------------------------------------------
DEFINE FONT oFntMetroNormal2 NAME "TAHOMA" SIZE 0,-22
DEFINE FONT oFntMetroMedium2 NAME "TAHOMA" SIZE 0,-32
DEFINE FONT oFntMetroFLATBTN NAME "TAHOMA" SIZE 0,-18
oFntMetroSay := TFont():New( "Calibri", 0, -13, .F.,.F.,0,0,,.F.,.F.,.F.,0,3,2,1,,34 )
//cAnzeige1 := ansiToOem(cAnzeige1)
nLine := 16
DEFINE DIALOG oDlg ;
TITLE "Auswahl" ;
FROM 0, 5 ;
TO nHeight*1/2, nWidth + 6 ;
PIXEL ;
STYLE nOr( DS_MODALFRAME, WS_POPUP ) ;
COLOR CLR_WHITE, nRibbonTopClr ;
FONT oFntMetroFLATBTN
oDlg:SetFont( oFntMetroNormal2 )
nLine := 0.5
@ nRowOffset * nLine , nWidth/5/2.05 ;
SAY cTitel ;
OF oDlg ;
PIXEL ;
FONT oFntMetroMedium2 ;
COLOR CLR_WHITE, nRibbonTopClr
nLine := 2
@ nRowOffset + nRowSpace * nLine,nWidth/5/2.05 ;
SAY cAnzeige1 ;
OF oDlg ;
PIXEL ;
FONT oFntMetroMedium2 ;
COLOR CLR_WHITE, nRibbonTopClr ;
SIZE 600, 600
*----------------------------------------------------------
@ ( nHeight*1/2 - 45 ) / 2.05,nWidth/5/2.05 ;
FLATBTN oBTNNaviWeiter ;
PROMPT "OK" ;
FONT oFntMetroFLATBTN ;
SIZE 2, ( 32 ) /2.05 ;
OF oDlg ;
ACTION ( lVar := .T., oDlg:End() ) ;
COLOR nRibbonTopClr, RGB( 210, 210, 210 ) ;
DEFAULT
@ 0,0 ;
FLATBTN oBTNNaviInfo ;
PROMPT "+" ;
FONT oFntMetroSay ;
SIZE ( 32) /2.05 , ( 32) /2.05 ;
OF oDlg ;
ACTION ( msginfo( cInfo ) ) ;
COLOR nRibbonTopClr, RGB( 210, 210, 210 )
oBTNNaviInfo:cTooltip := {"Info"}
ACTIVATE DIALOG oDlg CENTERED
RETURN NIL
//----------------------------------------------------------------------------//
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
Re: PRINT class printer options
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.
Here is the PrnSel( ) function code:
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:
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
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
// 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
Code: Select all | Expand
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 )
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
// Obtain old printer
cOldPrinter := WIN_PRINTERGETDEFAULT( )
// Set to default printer
WIN_PRINTERSETDEFAULT( cUsePrint )
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
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit