Frage Deutsch
~~~~~~~~~~~~~~
Wie kann mein QB-Programm etwas auf einen Windows-Drucker ausgeben?
Wie kann ich etwas auf einen Windows-Drucker xyz ausgeben?
Wie kann ich aus meinem QBasic-Programm heraus meinen Windows-Drucker
anprechen und Text und Grafik ausdrucken, die mein Programm erzeugt hat?
 

Question English
~~~~~~~~~~~~~~
How can my QBasic program print out text and graphics on a windows printer?
 

Antwort 1
~~~~~~~~
[ von Thomas Antoni, 12.6.2002 ]

.
Mit dem PRINT-Befehl von QBasic kann man ohne weitere Vorverarbeitung nur solche Drucker ansprechen, am parallelen Drucker-Port hängen und die die DOS ASCII-Zeichen verstehen. Das ist z.B. bei solchen Druckern der Fall, die Kompatibilitätsmodi zur Emulation eines "IBM Proprinter" oder "Epson RX 80" besitzen.
 
Wenn Dein Drucker ein einfaches Treibermodell mit einem simplen Satz von Steuerbefehlen hat, kannst Du Dir vielleicht einen eigenen kleinen Treiber programmieren. Die Steuerbefehle sind häufig als "Escape-Sequenzen" ausgelegt und in einem zusammen mit dem Drucker ausgelieferten Programmierhandbuch beschrieben. Mit diesen Steuerbefehlen kannst Du z.B. die Schrift auf schmal, fett, kursiv, gesperrt und groß/klein umstellen und auf Querdruck umschalten. Auch Grafikdruck ist damit normalerweise möglich.
 
Hast Du aber einen Drucker, der nur mit einem Windows-Treiber betrieben werden kann oder einen dieser Billig-Laserdrucker mit einem "Windows Printing System", d.h. ohne einen eigenen Prozessor, dann kommst Du mit den QBasic-Bordmitteln nicht weiter. Ebenso, wenn der Drucker am USB-Port hängt, weil es für USB keinen einfach zu hantierenden USB-Treiber für DOS gibt.
 
In solchen Fällen rate ich Dir zu der Verwendung des "
RGH-Drucksystems". Du kannst es auf meiner Seite http://www.qbasic.de in der Rubrik "QBasic -> Download -> Sonstiges" herunterladen. Dem Downloadarchiv liegt ein von mir geschriebenes QBasic-Beispielprogramm zur Druckerausgabe bei.
 
*** Auf www.qbasic.de beschreibe ich das RGH-Drucksystem wie folgt
Ein Traum wird wahr: Aus QBasic heraus auf jeden beliebigen Windows-Drucker Texte und Grafiken ausdrucken ! Das RGH-Drucksystem macht es möglich ! Läuft unter Windows 9x/ME/NT 4/2000/XP. Mit "Drucker einrichten ..." Dialog !
 
RGH-Druck besteht aus 3 Komponenten:
DRwahl.exe - Öffnet den normalen Windows-Dialog "Drucker einrichten"
RGHlist.exe - Zeigt eine Druckvorschau auf dem Bildschirm an
RGHdruck.exe - Das eigentliche Druckprogramm
 
RGH-Druck unterstützt ASCII- und ANSI-Dateien, viele Schriftarten und -größen sowie Vektor- und Pixelgrafiken - und das sowohl in schwarz/weiß als auch in Farbe. RGHDRUCK ermöglicht es jedem DOS-Programm, formatierte Windows-Ausdrucke zu erzeugen, ohne daß eine Textverarbeitung bemüht werden müßte oder man irgendetwas über den angeschlossenen Drucker wissen muß. Zur Demonstration der Leistungsfähigkeit von RGH-Druck druckt das Demoprogramm QBDRUCK.BAS das Inhaltsverzeichnis eines wählbaren Verzeichnisses aus.
 
Übrigens: RGH-Druck wurde geschrieben von Roland G. Hülsmann, dem Schöpfer von Profan². Profan² ist die ideale Windows-Programmiersprache für Einsteiger und auch besonders für Aufsteiger von QBasic geeignet. Besuche unbedingt Rolands Webseite
http://www.profan.de , um mehr über Profan² zu erfahren !
 
 
Antwort 2
~~~~~~~~~~~~~
[ von Neo386 ( webmaster*cwsearch.de ) im QB-Forum, 1.11.2003 ]
 
*** Frage
Wie funktioniert Drucken auf USB-Drucker im Hintergrund?
Hallo! Kennt jemand noch ein anderes QBasic-taugliches Druck-Tool außer RGH-Druck, weil da funktioniert das Drucken im Hintergrund nicht, ich wüsste jedenfalls nicht wie! Im Endeffekt möchte ich eine Textdatei auf einem beliebigen an Windows angeschlossenen Drucker (egal ob parallel oder USB) IM HINTERGRUND, also ohne dass mein Programm wärend des Druckvorganges minimiert wird, drucken.
Für Vorschläge wär ich extrem dankbar!!!!
 
*** Antwort
Unter Windows gehts ganz einfach so...
 
Zunächst schreibst Du Deinen gesamten Text in eine Datei (ist am besten, damit der gesamte Text gedruckt wird und nicht für jede Zeile eine Seite gedruckt wird).
 
Open "C:\Print.tmp" for output as #1
Print #1, "blablabla"
'Hier kommen weitere Zeilen rein, die gedruckt werden sollen
'
Close #1
'
Shell "copy c:\print.tmp > prn" 'Hier wird die Datei an den Windows-
'Standarddrucker gesendet (funktioniert
'natürlich nur bei geladenem Windows).
 
Wird dabei eine Fehlermeldung ausgegeben? Dann müssen möglicherweise einige Einstellungen in den Druckeroptionen geändert werden. Ich glaub ab Windows 2000 (SP3?) oder XP ist das notwendig geworden und da muss dann für DOS noch etwas extra aktiviert werden.
 
Ansonsten kannst Du das gleiche Script nochmals probieren, aber anstelle von prn auf "LPT1" linken. Möglicherweise wird der LPT1-Port vom Druckertreiber emuliert.

 

Answer 3
~~~~~~~~~~~
[ from the QB-Forum-FAQ at www.network54.com/Forum/ ]
 
*** Question
How to print something to a Windows printer?
 
 
*** Answer
Following only tested for Win98SE. If you tried it in any other version of windows, please tell your experiences!
 
 
*** 1. Using Wordpad
If you use the OPEN "LPTn:" option to print, which is preferable anyway,
very little change is needed to support all kinds of windows printers, including USB printers and specialized printerdrivers (such as PDFWriter or FinePrint).
Simply replace the LPTn: or PRN: in the OPEN statement with a filename such as Temp.txt. The output is put into a textfile. To print it with any windows printer, use this:
 
SHELL "start /m wordpad /p Filename.TXT"
 
This starts the wordpad program with the /p switch, which means that wordpad will load the file, print it and ends its operation. However it will only work for the printer that is set as Default.
The output is printed in Courier New, so its still non-proportional as it would be if you send the characters directly. However, it's probably printed much smaller than the printer's standard font.
 
Wordpad will recognize most control characters, so any NewPage characters (CHR$(12) ) will still work! So this way is best for applications that require a specific page lay-out, like forms in a Cash Register program.
 
Here is some code that will print 2 test pages:
a = FREEFILE
OPEN "Temp.TXT" FOR OUTPUT AS #a
PRINT #a, "Test" + CHR$(12) + "test"
CLOSE #a
SHELL "start /m wordpad /p Temp.TXT"
 
It should be noted that it has the annoying effect of minizing QBasic if it is Full Screen. If you use it in a Windowed (text) screen however printing will stay nicely in the background.
 
 
*** 2. Using Notepad
You can use the same method as in #1, but use Notepad instead of Wordpad. It recognizes the /p switch too!
 
Using Notepad will get a different result: control characters don't control the printer, but instead print as printable characters. Also, Notepad adds the filename and the page number by default. You might want to use a filename without extension with an 8 letter title as the name.
 
The coolest option of using Notepad is that it prints in the font you set in the "Edit--> Font" menu. You can choose any font that is installed including all those beautiful Truetype fonts for the print out of your QBasic program by simply changing this option in Notepad.
 
Use this way to print out any text that has no specific page setup, like a help file or program output.
 
 
*** 3. Using Wordpad with RTF files
Instead of just using Wordpad for text files, you can also use QBasic to write RTF files, in which you can use all the fonts and lay-out effects you want. There are lots of sites on the internet that explain the different RTF commands.
 
There is a simpler way though. Just use Wordpad to make a nice layout using pieces of text you can easily recognize. The texts might be something like XXXXXXXXX or YYYYYYYY or something. Save the file in RTF format. All you have to do is write a program that replaces the XXXXXXXXX and YYYYYYYY for different text segments, OPEN the text for OUTPUT as before, and just use the SHELL "start /m wordpad /p Temp.RTF" command.
 
You can even put the RTF code in the QBasic code itself in strings. Suppose this is the RTF code:
 
{\rtf1\ansi\ansicpg1252\deff0\deflang1043{\fonttbl{\f0\froman\fprq2\fcharset0 Bookman Old Style;}{\f1\fnil\fcharset0 Times New Roman;}{\f2\froman\fprq2\fcharset0 Book Antiqua;}}\viewkind4\uc1\pard\b\f0\fs144 AAAAAAAAA\b0\f1\fs20\par\par\i\f2\fs24 BBBBBBBBB\i0\f1\fs20\par\par\f2 \par CCCCCCCCC\f1\par\par\i DDDDDDDDD\i0\par}
 
You can then put the RTF code in strings like this:
 
A$="{\rtf1\ansi\ansicpg1252\deff0\deflang1043{\fonttbl{\f0\froman\fprq2\fcharset0 Bookman Old Style;}{\f1\fnil\fcharset0 Times New Roman;}{\f2\froman\fprq2\fcharset0 Book Antiqua;}}\viewkind4\uc1\pard\b\f0\fs144 "
B$="\b0\f1\fs20\par\par\i\f2\fs24 "
C$="\i0\f1\fs20\par\par\f2 \par "
D$="\f1\par\par\i "
E$="\i0\par}"
 
You can now put the text you want the computer to print in strings:
Title$="This is the Title"
Intro$="We start with a small intro..."
Main$="This is the main text. You can make it as long as you want. With \par you get a new paragraph."
Last$="This is just the text to end it."
 
 
Put all of it together like this:
Text$=A$+Title$+B$+Intro$+C$+Main$+D$+Last$+E$
 
Save it to a file:
a=FREEFILE
OPEN "temp.RTF" FOR OUTPUT AS #a
PRINT #a,Text$
CLOSE #a
 
And start wordpad to print:
 
SHELL "start /m wordpad /p temp.RTF"
 
 
And with a little bit of luck and some fiddling, your QBasic program can print with all the nice fonts Windows has to offer.
 
(Of course you can also use Word to make RTF files, however Word makes them very bloated and it isn't easy to use such enormous files.)
 
 
*** 4. Using Paint
But those are not the only programs that recognize the /p switch. Paint knows it too! This means that QBasic can print graphics as long as they are in BMP format. Like this:
 
SHELL "start /m " + CHR$(34) + "C:\Program Files\Accessories\MSPAINT.EXE" + CHR$(34) + " /p Filename.BMP"
'---(You may need to change the directory MSPAINT is in!)
 
Now we only need a good BMPWriter routine that works in all of QBasic's screenmodes, and QBasic can print out its graphics output with a simple command. Here you can find one:
www.network54.com/Hide/Forum/message?forumid=171757&messageid=1047447069
 
 
*** 5. Using Internet Explorer
This technique is similar to making RTF files and printing them through Wordpad with the /p switch. All you need to do is make sure the QBasic program writes an HTML file and in it you use all the layout you want. Here is an example of a very simple HTM file that is printed through internet explorer:
 
OPEN "C:\temp.HTM" FOR OUTPUT AS #1
PRINT #1, "<html><body><h1>Hallo</h1></body></html>"
CLOSE #1
SHELL "rundll32.exe C:\WINDOWS\SYSTEM\MSHTML.DLL,PrintHTML c:\temp.HTM"
 
Notice that windows treats this SHELL command very differently. Instead of printing directly through the standard printer, the print dialog comes up! You can now choose all the settings you want before printing, even choose another printer.
 
Of course, you can print simple .TXT files the same way.
 
Internet Explorer however, puts on default some information on the page, like the title, date and full name and path of the file. You'll have to change the settings if you don't want this.
 
Great advantage of this method is, that you can easily print graphics and text at the same time by including <IMG> tags. HTML is much easier that RTF anyway, but you can't include any hard page seperations, since it isn't a lay-out language.
 
There: five great ways to make QBasic print in Windows. All have their advantages and disadvantages, and it may require some experimenting before you get satisfactory results.
 

[ The QBasic-MonsterFAQ --- Start Page: www.antonis.de/faq ]