It is currently Fri Jan 22, 2021 4:30 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: How to Select a non-default printer?
PostPosted: Fri Sep 20, 2019 4:55 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 21, 2009 6:56 pm
Posts: 598
Hi

Is there a command in Purebasic that can be used to select a printer that is not the default printer?

Thanks
Simon

_________________
Simon White
dCipher Computing


Top
 Profile  
Reply with quote  
 Post subject: Re: How to Select a non-default printer?
PostPosted: Fri Sep 20, 2019 6:51 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2817
Location: Germany
Only over "PrintRequester()"

We can't save last selected printer for next printing... :(

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: How to Select a non-default printer?
PostPosted: Sat Sep 21, 2019 2:40 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 21, 2009 6:56 pm
Posts: 598
Hi

That is too bad because I often need to do it without user interaction when reports are automated.

Simon.

_________________
Simon White
dCipher Computing


Top
 Profile  
Reply with quote  
 Post subject: Re: How to Select a non-default printer?
PostPosted: Sat Sep 21, 2019 3:07 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2817
Location: Germany
It's been on the wish list a long time.
There was a procedure somewhere for windows to change the default printer...

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: How to Select a non-default printer?
PostPosted: Sun Sep 22, 2019 1:12 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 2:15 pm
Posts: 901
Location: Cuernavaca, Mexico
Here's something from Sparkie and Gnozal that can find my default printer
and may point you in the right direction...

Code:
; *****************************************************
; Code    : Print Text File
; Author  : Sparkie
; Date    : December 2, 2006
; OS      : Windows NT, 2000, XP, 2003, Vista
; PB Ver  : 4.01
; License : It's all yours to use as you so desire
;           (props/credit are welcome)
; *****************************************************

If OSVersion() =  #PB_OS_Windows_95 Or OSVersion() =  #PB_OS_Windows_98 Or OSVersion() =  #PB_OS_Windows_ME
  MessageRequester("Error", "Requires Win/NT, 2000, XP, 2003, or Vista", #MB_OK | #MB_ICONERROR)
  End
EndIf

;...Procedure to select text file to print
Procedure PrintThis()
  Pattern$ = "Text (*.txt)|*.txt;*.bat|PureBasic (*.pb)|*.pb|All files (*.*)|*.*"
  Pattern = 0    ; use the first of the three possible patterns as standard

  file$ = OpenFileRequester("Select File", "", Pattern$, Pattern)
  printer$ = Chr(34) + GetGadgetText(1) + Chr(34)
  result = ShellExecute_(0, "printto", file$, printer$, "", #SW_HIDE)
  If result <> 42
    strmsg.s = "Detected an error from ShellExecute... error number:" + Str(result)
    MessageRequester("Error", strmsg, #MB_OK | #MB_ICONERROR)
  EndIf
  ProcedureReturn result
EndProcedure

;...Procedure to get printer names for use with "printto"
Procedure GetPrinters()
  result.l = 0
  numPrinters.l = 0
  bytesCopied.l = 0
  ;...Enum printer names as we need string names to use "printto"
  If EnumPrinters_(#PRINTER_ENUM_NAME, "", 5, 0, 0, @bytesCopied, @numPrinters) = 0
    items.l = Round(bytesCopied / SizeOf(PRINTER_INFO_5), 1)
    Dim pi5.PRINTER_INFO_5(items)   
    If EnumPrinters_(#PRINTER_ENUM_NAME, "", 5, @pi5(), bytesCopied, @bytesCopied, @numPrinters) <> 0
      ;...Credit for getting Default Printer goes to gnozal :)
      buff$ = Space(260)
      If GetPrivateProfileString_("WINDOWS", "DEVICE", "", @buff$, 260, "Win.Ini")
        defPrinter$ = StringField(buff$, 1,",")
      EndIf
      ;...Fill our ComboGadget with printer name(s)
      For i = 0 To numPrinters - 1
        AddGadgetItem(1, -1, PeekS(pi5(i)\pPrinterName))
        If defPrinter$ = PeekS(pi5(i)\pPrinterName)
          SetGadgetState(1, i)
        EndIf
      Next i
      DisableGadget(2, 0)
      result = 1
    Else
      result = 0
      MessageRequester("Error", "Could not find printer(s)", #MB_OK | #MB_ICONERROR)
      DisableGadget(2, 1)
    EndIf
  EndIf
  Dim pi.PRINTER_INFO_5(0)
  ProcedureReturn result
EndProcedure
 
If OpenWindow(0, 0, 0, 300, 130, "Print Text File", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
  TextGadget(0, 10, 20, 100, 20, "Select Printer")
  ComboBoxGadget(1, 10, 40, 200, 20)
  ButtonGadget(2, 10, 80, 100, 25, "Select file to print")
  GetPrinters()
 
  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_Gadget And EventGadget() = 2
      PrintThis()
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf
End

_________________
- It was too lonely at the top.

Current Machine: Win 10 Pro 64-bit, Dual Xeon E5-2670, 64 gigs ram, Geforce GTX 1660 Ti w/6 gigs ram


Top
 Profile  
Reply with quote  
 Post subject: Re: How to Select a non-default printer?
PostPosted: Sun Sep 22, 2019 8:28 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1791
Location: Germany
swhite wrote:
Is there a command in Purebasic that can be used to select a printer that is not the default printer?

There is no command in PureBasic. But for Windows you may try one of the following old examples using API commands to set a new default printer. So in effect you would read and store the current default printer, change the default printer and after your printing job you would restore the previous default printer.
- shim
- Rings
- ts-soft
- hjbremer
- Max_der_Held


Top
 Profile  
Reply with quote  
 Post subject: Re: How to Select a non-default printer?
PostPosted: Tue Sep 24, 2019 1:45 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 21, 2009 6:56 pm
Posts: 598
Now that I know there is no command to choose a printer without user interaction I will use the Windows API.

Thanks
Simon

_________________
Simon White
dCipher Computing


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 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