Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get Windows Default printer

Status
Not open for further replies.

Sammybobo

Programmer
Apr 4, 2003
87
US
How could I get VFP to pass the default printer to a variable or parameter without showing the printer dialog box, as "cPrinter = GETPRINTER()" would. I need to know this for Win 95,98,2000, and XP. Thanks.

Sammybobo
 
According to the help file

?SET('PRINTER', 2) Default Windows printer name
?SET('PRINTER', 3) Default Visual FoxPro printer name

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Either or those gave me "PRN." But what I am looking for is to have a way for VFP to return the name of my default printer on the machine, e.g. "HP Laserjet 1000", so that I can pass the name as a parameter and prevent VFP from throwing a dialog box at me. Thanks.

Sammybobo
 
Sammybobo,

I'm not sure I'm following. The code that mgagnon gave you is correct. If the machine has a default printer set up then Set('Printer',2) will return the name just as you've asked for. If there isn't a print driver installed on the machine, then you won't be able to retrieve the name as it doesn't exist. Even if the printer is being accessed over a network (is connected to another machine), the code that mgagnon gave you will work...it will return the UNC path to the device.

Perhaps we're not understanding exactly what you want?

boyd.gif

 
Have you looked at the APRINTERS() function? The name of the printer is in the first entry and the port is in the second. In VFP 9.0, you can get even more information with an optional parameter.

Rick
 
Thanks for your comments. The problem I am having is finding a way to actually put the printer name in the code. For instance, in faq184-5014, Mike used the code:

lcPrinter = GETPRINTER()
nHDC = CreateDC(0,lcPrinter,0,0) && Get the printer handle

That works fine but the printer dialog is displayed first. But I don't want the dialog to show in this case, so I substitute the printer name as follows:

*lcPrinter = GETPRINTER()
nHDC = CreateDC(0,"HP Laserjet 1000",0,0) && Get the printer handle

That would let me print directly without getting the dialog first. So, I want to get the code for a reference to the default printer so I can pass it to the "nHDC" for the printer on the user machine. Thanks.

Sammybobo
 

Then use :
Code:
lcPrinter= SET('printer',2)  & Default windows printer
nHDC = CreateDC(0,lcPrinter,0,0)  && Get the printer handle






Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks, Mike! I'll try that. God bless.

Sammybobo
 
I use a combination of the above suggestions and some Windows scripting suggested elsewhere on this forum to do the following:

Code:
* - Determine Existing Default Windows Printer -
lcDefaultPrinter =  SET("PRINTER",2)

* - Use APRINTERS() To Determine What Printers Available -
=APRINTERS(aryPrinters)

lcNewPrinter = "Image Printer"
IF ASCAN(aryPrinters, UPPER(lcNewPrinter)) > 0
  * - Use Windows Scripting To Set Default Printer To New Image Printer -

  oNET = CREATEOBJECT("WScript.Network")
  oNET.SetDefaultPrinter(lcNewPrinter)

  SET PRINTER TO NAME (lcNewPrinter)

  * < Do Whatever >
  * Such as . . . 
   SELECT MyTable
   REPORT FORM MyReport NOCONSOLE TO PRINTER

  * - When Done Printing - 
  * - Use Windows Scripting To Restore Orig Default Printer -
  oNET.SetDefaultPrinter(lcDefaultPrinter)
  RELEASE oNET

  SET PRINTER TO NAME (lcDefaultPrinter)
ENDIF  && IF ASCAN(aryPrinters, UPPER("Image Printer"))

This enables me to programatically control the specific printer used for a specific task.

Good Luck,
JRB-Bldr


JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top