Re: Printer selection
Posted: Tue Jul 27, 2004 3:51 pm
I think this should work with all Windows versions :schim wrote:Hi!
How can I select a printer without using the print requester?
Default printer works, but I have to set diffrent printers.
There is an example but it only works on W2K (or W98) because the script grapped out the printernames from the win.ini-File.
Perhaps someone has a solution?
Thanks
schim
Code: Select all
NewList Imprimantes.s()
Procedure.l GetInstalledPrinters() ; in linked list Imprimantes()
ClearList(Imprimantes())
Buffersize.l = 8102
*Buffer = GlobalAlloc_(#GMEM_FIXED | #GMEM_ZEROINIT, Buffersize)
TempPrinter.s = Space(1024)
If GetProfileString_("devices", 0, "", *Buffer, Buffersize)
TempString.s = PeekS(*Buffer)
Length.l = Len(TempString)
While TempString <> ""
GetPrivateProfileString_("devices", TempString, "", TempPrinter, 1024, "Win.Ini")
; Debug "Device : " + TempString
; Debug "Driver : " + StringField(TempPrinter,1,",")
; Debug "Port : " + StringField(TempPrinter,2,",")
AddElement(Imprimantes())
Imprimantes() = TempString
TempString = PeekS(*Buffer + Length + 1)
Length = Length + Len(TempString) + 1
Wend
EndIf
GlobalFree_(*Buffer)
ProcedureReturn CountList(Imprimantes())
EndProcedure
;
Procedure.s GetDefaultPrinter()
STDPrinterName$ = Space(260)
If GetPrivateProfileString_("WINDOWS","DEVICE","", @STDPrinterName$, 260, "Win.Ini")
ImprimanteParDefaut.s = StringField(STDPrinterName$, 1,",")
EndIf
ProcedureReturn ImprimanteParDefaut
EndProcedure