Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to set any printer as the current Windows printer?
Message
From
13/02/1999 07:57:57
 
 
To
13/02/1999 04:04:52
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00187351
Message ID:
00187359
Views:
20
>I would like to know how I can set any installed Windows Printer as the current printer for VFP and for Windows, I used Getprinter but did not work. Is very important, I am finishing an application and this one is the last thing to terminate it. Tia
>

It's actually pretty trivial to do using APRINTERS(), and a registry key for the current user.

The registry key HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Print\Printers contains the list of currently defined printers for the user logged into the system. Each defined printer is listed as a subkey; this list is returned by APRINTERS() in the first column of the two dimensional array.

In the Printers registry key itself, there's a Registry Value called Default; this is a string registry value, which contains the name of the current default printer. If you write the name of the printer that you want to use as the default printer in this resitry key value, VFP (and all other WinApps) will use that printer as the default printer for the user.

The FFC Registry class in VFP 6 has all the functionality needed to set this registry value; it uses the Win32 API calls and provides a consistent method for manipulating the registry. In earlier versions, you'll need to use the Win32 API calls ; there are classes that can be downloaded from UT's file section with the necessary functionality. In pseudocode, what needs to be done is:
Construct a list of printer names known to Windows
Pick the printer to use the default, and save the name WIndows uses to reference it
Open the registry key HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Print\Printers using RegOpenKey()
Write the name of the desired printer to the registry value Default using RegSetValueEx()
Close the registry key using RegCloseKey()
Using the FFC, you'd use the OpenKey, SetKeyValue and CloseKey methods to open, write and close respectively.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform