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