PureBasic Forum https://www.purebasic.fr/english/ |
|
List installed printers / Set default printer https://www.purebasic.fr/english/viewtopic.php?f=12&t=6002 |
Page 1 of 1 |
Author: | gnozal [ Tue Apr 29, 2003 2:34 pm ] |
Post subject: | List installed printers / Set default printer |
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) |
Author: | Num3 [ Wed Apr 30, 2003 8:57 pm ] |
Post subject: | |
Excelent code !!! great help ![]() |
Author: | Karbon [ Thu Nov 04, 2004 7:15 pm ] |
Post subject: | |
Does anyone know of a way to do this that works with 2000+ ? |
Author: | El_Choni [ Thu Nov 04, 2004 7:32 pm ] |
Post subject: | |
Code: SetDefaultPrinter_(printername.s)
|
Author: | Karbon [ Thu Nov 04, 2004 7:36 pm ] |
Post subject: | |
Lets all pretend that I didn't just miss that. *crawls back under rock* |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |