Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using VFP (or Win32API) to set the default printer
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01143034
Message ID:
01143068
Views:
9
You don't really need it FoxPro knows what it with SET('Printer',2), here is how to do it
DECLARE INTEGER SetDefaultPrinter IN winspool.drv;
    STRING pszPrinter
LOCAL lcOldPrinter,lcNewPrinter
lcOldPrinter=SET("Printer",2)  && Default Windows Printer
lcNewPrinter=GETPRINTER()
=SetDefaultPrinter(lcNewPrinter)  && Switch
MESSAGEBOX(SET("Printer",2))
=SetDefaultPrinter(lcOldPrinter) && Switch back
MESSAGEBOX(SET("Printer",2))
>Thanks, Mike. That works well and was easy to do. :-)
>
>My only issue now is to determine the current default Windows printer (so I can set it back after I do what I need to do).
>
>I'm trying to use this to get the default printer name, but I'm having trouble implementing it.
>
>DECLARE INTEGER GetDefaultPrinter IN winspool.drv;
>    STRING  @ pszBuffer,;
>    INTEGER @ pcchBuffer
>
>Parameters:
>
>pszBuffer
>[in] Pointer to a buffer that receives a null-terminated character string containing the default printer name.
>pcchBuffer
>[in/out] On input, specifies the size, in characters, of the pszBuffer buffer.
>
>Any suggestions? In other words, I'm not sure what values I need to pass it to return the name of the current default Windows printer.
>
>Thanks,
>
>
>>
DECLARE INTEGER SetDefaultPrinter IN winspool.drv;
>>    STRING pszPrinter
>>
>>Will change you Windows default printer.
>>
>>
>>>I am attempting to change the default printer, print, then change it back (without displaying any dialogs, etc).
>>>
>>>Assuming MytempPrinter is the name of the installed printer I want to print to, this is easy to do in VFP using:
>>>
>>>
>>>* Change to the printer I need to print to
>>>Set Printer to Name "MytempPrinter"
>>>
>>>* execute code that prints, etc.
>>>
>>>* Change back to the default printer
>>>Set Printer to Default
>>>
>>>
>>>However, the code above will only affect printing from VFP. Since I am using automation to control Excel and calling the printing from Excel (not VFP), my output is routed to the Windows default printer, not the printer I set to in VFP.
>>>
>>>Does anyone have sample code (using WIN32 API, etc) that will allow me to silently get the name of the current Windows default printer, change the Windows default printer to another printer, then change it back to the original?
>>>
>>>Thanks,
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform