Printing from report preview.

User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

James Bott wrote:Enrico,

I have made the changes you suggested but the routine is not restoring the original printer. Ideas?
You don't need to restore anything as the routine doesn't change the windows default printer nor the application default printer. Try this:

Code: Select all

#include "fivewin.ch" 

function main() 
   local oWnd 
   define window oWnd 
   activate window oWnd on init doit() 

return nil 

function doit() 

   local cPrinter:= "Your alternate printer" //prnGetName() 

//   printerSetup() 
   msgInfo( prnGetName() ) 

   setPrinter( cPrinter ) 
   msgInfo( prnGetName() ) 

return nil 



//--- Set application's current printer. Returns .T. if successful. 
// Author: James Bott, jbott@compuserve.com 
function setPrinter( cPrinter ) 
   local hDC:=0, aPrn, cText:="", lSuccess:=.f., cDriver:="", cPort:="" 

   if cPrinter <> prnGetName() 

      cText := StrTran(GetProfString("Devices"),Chr(0), chr(13)+chr(10)) 
      aPrn  := Array(Mlcount(cText, 250)) 
      Aeval(aPrn, {|v,e| aPrn[e] := Trim(Memoline(cText, 250, e)) } ) 

      if  ascan(aPrn,cPrinter) > 0 

         // Code by Enrico Maria Giordano 
         cDriver := StrToken( GetProfString( "Devices", cPrinter, "" ), 1, "," ) 
         cPort   := StrToken( GetProfString( "Devices", cPrinter, "" ), 2, "," ) 
         hDC := CreateDC( cDriver, cPrinter, cPort ) 

sysrefresh() 

msgInfo( cDriver, "cDriver") // returns "winspool" 
msgInfo( cPort, "cPort") // returns "Ne00:" 
msgInfo( hDC, "hDC" ) // sometimes positive, sometimes negative 

         if hDC != 0 
            lSuccess := DeleteDC( hDC ) 
         endif 
         sysRefresh() 

      endif 

   endif 

return lSuccess
EMG
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

James Bott wrote://--- Set application's current printer. Returns .T. if successful.
This comment is wrong. The routine doesn't change the application's current printer. Its purpose is to print to a printer different from the default one without change it.

EMG
Post Reply