FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Printing from report preview.
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Printing from report preview.
Posted: Sat Jun 14, 2008 12:39 PM
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:

#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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Printing from report preview.
Posted: Sat Jun 14, 2008 12:41 PM
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

Continue the discussion