It is currently Thu Feb 25, 2021 6:05 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: List installed printers / Set default printer
PostPosted: Tue Apr 29, 2003 2:34 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4229
Location: Strasbourg / France
Code updated For 5.20+

This is an exemple how to get a list of the installed printers and how to set one to the default windows printer.
Is there a more 'clean' way, without using WIN.INI and working with all windows versions (95/98/Me/NT/2K/XP) ?
Code:
; ---------------------------
; 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
Global NewList Printers.Printers()
; ------------
; Get installed printers
Procedure GetPrinterList()
 
  ClearList(Printers())
 
  Buffersize.l  = 8102
  *Buffer       = AllocateMemory(Buffersize,0)
  TempPrinter.s = Space(1024)
 
  If GetProfileString_("devices",0,"",*Buffer,Buffersize)
    TempString.s = PeekS(*Buffer)
    Length = Len(TempString)
    While TempString <> ""
      GetPrivateProfileString_("devices",TempString,"",TempPrinter,1024,"Win.Ini")
      AddElement(Printers())
      Printers()\P = TempString+","+StringField(TempPrinter,1,",")+","+StringField(TempPrinter,2,",")
      TempString = PeekS(*Buffer+Length + 1)
      Length = Length + Len(TempString) + 1
    Wend
  Else
    MessageRequester("Error","No printer installed",64)
  EndIf
 
  FreeMemory(*Buffer)
 
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)



Last edited by gnozal on Fri Nov 05, 2004 8:35 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Apr 30, 2003 8:57 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:51 pm
Posts: 2811
Location: Portugal, Lisbon
Excelent code !!!

great help :mrgreen:

_________________
Elevator Maintenance: http://central-elevadores.pt
Good web hosting![/size]


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 04, 2004 7:15 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Mon Jun 02, 2003 1:42 am
Posts: 2010
Location: Ashland, KY
Does anyone know of a way to do this that works with 2000+ ?

_________________
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 04, 2004 7:32 pm 
Offline
TailBite Expert
TailBite Expert

Joined: Fri Apr 25, 2003 6:09 pm
Posts: 1007
Location: Spain
Code:
SetDefaultPrinter_(printername.s)

_________________
El_Choni


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 04, 2004 7:36 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Mon Jun 02, 2003 1:42 am
Posts: 2010
Location: Ashland, KY
Lets all pretend that I didn't just miss that.

*crawls back under rock*

_________________
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Kwai chang caine and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye