More printer functions!

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
jvalks
User
User
Posts: 17
Joined: Thu Jun 05, 2003 12:47 pm

More printer functions!

Post by jvalks »

Please add more printer functions!

I like to read how many & which printers are installed, and select one of them to print to....
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Yes, it would be nice.

But you can do it allready (with API stuff) :

Code: Select all

; ---------------------------
; LIST ALL INSTALLED PRINTERS
;  AND SET DEFAULT PRINTER
; ---------------------------
;
; Adapted from VB source ...
; http://www.freevbcode.com/ShowCode.Asp?ID=641
;
; Printer list structure & list
Structure Printers
 P.s
EndStructure
NewList Printers.Printers() 
; ------------
; Get installed printers
Procedure GetPrinterList()

 ClearList(Printers()) 
 
 Buffersize.l  = 8102
 *Buffer       = AllocateMemory(0,Buffersize,0)
 TempPrinter.s = Space(1024)

 If GetProfileString_("devices",0,"",*Buffer,Buffersize)
  TempString.s = PeekS(*Buffer)
  Length = Len(TempString)
  While TempString <> ""
   ;Debug "Device  : "+TempString
   GetPrivateProfileString_("devices",TempString,"",TempPrinter,1024,"Win.Ini")
   ;Debug "Driver  : " + StringField(TempPrinter,1,",")
   ;Debug "Port    : " + StringField(TempPrinter,2,",")
   AddElement(Printers()) 
   Printers()\P = TempString+","+StringField(TempPrinter,1,",")+","+StringField(TempPrinter,2,",")
   TempString = PeekS(*Buffer+Length + 1)
   Length = Length + Len(TempString) + 1
   TempString = PeekS(*Buffer+Length + 1)
  Wend
 Else
  MessageRequester("Error","No printer installed",64)
 EndIf

 FreeMemory(0)
 
EndProcedure
; ------------
; Set default printer (should work for all windows versions)
Procedure SetDefaultPrinter(DeviceLine.s)

 ;DeviceLine=PrinterName,DriverName,PrinterPort
 ;Store the new printer information in the
 ;[WINDOWS] section of the WIN.INI file for
 ;the DEVICE= item
 WriteProfileString_("windows", "Device", DeviceLine)
  
 ;Cause all applications To reload the INI file
 SendMessage_(#HWND_BROADCAST, #WM_WININICHANGE, 0, "windows")
 
EndProcedure
; ------------
; MAIN

; Get installed printers
GetPrinterList()
; List the printers
ResetList(Printers())
Debug "Printers list :"
While NextElement(Printers())
 Debug Printers()\P  
Wend
Debug "---------------"
Debug "Make n°5 as default Printer"
SelectElement(Printers(), 4)
Debug "This is "+Printers()\P
SetDefaultPrinter(Printers()\P)
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post by NoahPhense »

Yeah, I found this in the codearchive..

What I would like to do, is change from the Default Printer, and make
another printer the Default Printer, then change back to the 'original'
default printer.. this code is great.. I'm going to use it..

But, it just doesn't let you know which printer is the default printer..

- john
Post Reply