Announcement

Collapse
No announcement yet.

Finding default printer (using XPrint)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Finding default printer (using XPrint)

    Hi,

    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.

    Code:
    #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   
       Next
       
       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?

    Thanks,
    Paul Squires
    FireFly Visual Designer (for PowerBASIC Windows 10+)
    Version 3 now available.
    http://www.planetsquires.com

  • #2
    The deceptively-named 'GetDefaultPrinter()' WinAPI function sure sounds promising...
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      I wrote an article for Paradox programmers on this subject at:

      ------------------------------------------------------------
      sigpic

      It has come to my attention that certain dubious forces are interpolating their desires in my search for Mom, apple pie and the girl you left behind. Stop it or I'll scream...

      Comment


      • #4
        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.
        Paul Squires
        FireFly Visual Designer (for PowerBASIC Windows 10+)
        Version 3 now available.
        http://www.planetsquires.com

        Comment


        • #5
          For Win9x/ME, you can use the Common Dialog "PrintDlg" with the PD_RETURNDEFAULT flag in the PRINTDLG structure......
          PD_RETURNDEFAULT
          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

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment

          Working...
          X