Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Under Windows

Status
Not open for further replies.

vince07

Programmer
Jan 10, 2002
3
NL
Hi,

Probably this item was mentioned before, but I could not find it.
The problem I encounter is that my Clipper(5.2d) program refuses to print under Windows(98). All I want it to do is to print some plain Ascii-reports. I allways write the the (ascii)reports to a file, show it on the screen, and then the I can decide to have it printed by pressing a function-key. That key activates the code to read the file, line by line, and send every line to printer. I used to write it to portnr. 4 but also a copy to the prn/lpt1 device doesnot seem to work.
This works fine under DOS, but not in Windows. Nothing happens then on the printer. Do I need to get myself a Windows-printer? Or do I have to change some code? Or what??
Anyone any idea.
thanks!
vince

 
The way I was able to get around this problem was to OVERLAY() out to a batch file that directed the file I wanted to print to the proper server and queue. I was working with a Netware network, but if you aren't just have OVERLAY() send it to the local LPT1: or PRN:.

Best of luck!!
 

Sorry, I don't know how to Overlay() to a batch file.
I assume overlay() is a function, but where to find it.
I use Blinker to create the executable. But Blinker not Funcky, not Clipper has got overlay() functions. As far as I know.
Can you help me further?
thanx.
 
This is a very basic procedure to print under Windows, Lantastic, Novell, DOS...

I extract this code from my own library, so you can adapt it to your desire.

You can use it to write a "black box function" or generic function as I do, so you simple pass parameters as File name, port etc. and re-use it.

Study the code and give it a try...

// Autor: Pablo Rodriguez Montenegro Castro. //
// Creada el 7/09/97 a las 7:44PM

// Select to wich port we are going to print...
Do Case
Case iPuerto == 1
Set Printer to ('LPT1')

Case iPuerto == 2
Set Printer to ('LPT2')

Case iPuerto == 3
Set Printer to ('LPT3')
End Case

Set Console off
Set Device To Printer
Set Printer on

// Get a handle to file...
cFile := "Your report's file name.ext"
aiHandle := fopen( cFile, 0 )

// Read each line in the file...
While !feof( aiHandle )
cLinea := freadline( aiHandle )

// See if the printer is online...
If isprinter( iPuerto)
// ^^ or whatever function you use to check if the printer is online

If Chr(12) $ cLinea
// Add CR + LF
cLinea += Chr(13) + Chr(10)
End If

Begin Sequence
// Print it...
qout( cLinea )
alImprimir := NO

Recover Using oErrLocal
// Cancel print job...
// Your code here...
alImprimir := NO
alCancelar := SI

End Sequence

Else
Inkey( 1 )
// Cancel print job...
// Your code here...
alImprimir := NO
alCancelar := SI
End If // Check port.

End Do // Loop to print each line.

If alCancelar
Exit
End If

alImprimir := SI
Inkey()

// If the user wants to quit...
If (LastKey() == K_ESC) .and. rpYesNo(,'¨Desea cancelar la impresi¢n del reporte?',NO)
print( 13, 24, ' ', 112, 40 )
print( 13, 25, ' Cancelando la impresi¢n... ', 79 )
Inkey( 1 )
Exit
End If

End Do // While not eof.

fclose( aiHandle )


// Flush the print buffer, so Win starts to print...
cDestino := set( _SET_PRINTFILE )

Begin Sequence
set( _SET_PRINTFILE, 'LPT3' )
End Sequence

Begin Sequence
set( _SET_PRINTFILE, 'LPT2' )
End Sequence

Begin Sequence
set( _SET_PRINTFILE, 'LPT1' )
End Sequence

Begin Sequence
set( _SET_PRINTFILE, '' )
End Sequence

// Restore the original print destination...
set( _SET_PRINTFILE, cDestino, .t. )

Eject // This is optional...

Set Printer off
Set Printer To
Set Device To Screen
Set Console on
 
Overlay() is a third party library you would need to purchase. It allows you to jump out of the program to run another program or some DOS commands. Then returns control back to your program to continue on.
 
You can visit www.softdesign.com to either download a demo or purchase a copy of Overlay()
 
This functionality is also built-in with Blinker, and it even 'tucks away' most of your app to EMS or XMS memory at need! so you can have over 550 kB of DOS memory available, look in the docs for SwpRunCmd() function and all that goes with it.

Good Luck,
TonHu
 
Hi Guys,

It seems I got the thing finally working, thanks to the SwpRunCmd() in Blinker. And to your suggestions. Thankx!
Vince
 
try this, it works great. I got it from another thread else where and felt compelled to post it here.
Works on XP and win 98. Solved my problem right away,
I was stuck with this problem for some time.


set printer to lpt1: // or whatever port is used
set device to printer
DoThePrinting()
eject
set device to screen
set printer to // this is where the port is closed
 
>> All I want it to do is to print some plain Ascii-reports. I allways write the the (ascii)reports to a file, show it on the screen, and then the I can decide to have it printed by pressing a function-key. <<

Have you tried printing your file from a WIN 98 DOS window with Notepad?

ex.: RUN (&quot;notepad /p &quot;+cFILENAME)

You may need to adjust your Notepad print settings to get the font and header/footers the way you want them.
 
Something you might want to consider. Create your ascii file report..then execute

&quot;notepad <yourfile>&quot;

the user can print .. or not.

Alternatively, use

&quot;wordpad <yourfile> /p&quot;

Make sure that wordpad is available..usually it is NOT in the default search paths.

What I like about using this is that the printer is under control of windows. If the user changes the default printer or wants a different font etc he can do so.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top