No announcement yet.

Finding default printer (using XPrint)

  • Filter
  • Time
  • Show
Clear All
new posts

  • Michael Mattias
    For Win9x/ME, you can use the Common Dialog "PrintDlg" with the PD_RETURNDEFAULT flag in the PRINTDLG structure......
    If this flag is set, the PrintDlg function does not display the dialog box. Instead, it sets the hDevNames and hDevMode members to handles to DEVMODE and DEVNAMES structures that are initialized for the system default printer. Both hDevNames and hDevMode must be NULL, or PrintDlg returns an error.
    Here's some code you can adapt if you have a burning desire to support Win 9x/ME..

    Initialize the Common Dialog's PrintDlg() for named printer 9-21-04


    Leave a comment:

  • Paul Squires
    hmmmmm, how about that - I never stumbled on that api. Looks like it is available for all NT based versions of Windows (Windows 95/98/Me not supported). Should be perfect for me because my program does not officially support Windows 95/98/Me anyway. Thanks Michael.

    Leave a comment:

  • Rick Kelly
    I wrote an article for Paradox programmers on this subject at:

    Leave a comment:

  • Michael Mattias
    The deceptively-named 'GetDefaultPrinter()' WinAPI function sure sounds promising...

    Leave a comment:

  • Paul Squires
    started a topic Finding default printer (using XPrint)

    Finding default printer (using XPrint)


    I have been trying to use the XPrint functions a lot lately in an effort to simplify my printing code. I have been using the following code to determine what the default installed printer is.

    #Compile Exe
    Function PBMain() As Long
       Local st As String
       Local y  As Long
       XPrint Attach Default, ""  
       For y = 1 To PrinterCount
          st = Printer$(Name, y) 
          If st = XPrint$ Then 
             MsgBox "Default print = " & st
             Exit For 
          End If   
       XPrint Close
    End Function
    The XPrint Attach Default seems to create a zero byte print job. That's not too big of a deal if the printer is turned on because it appears that the print job deletes itself once XPrint Close is encountered. My problem is when the printer is not turned on. The zero length print job will stay there until I have to manually delete it.

    Is there a better way to do my code above? Any other (simple) choices for determining the default installed printer?