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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Printer

Status
Not open for further replies.

FoxLearner

Programmer
Aug 29, 2002
93
0
0
US
Hi Folks

I gess today is not very good for me. This is my third problem today.

Can any one tell me how to set the printer to windows default? I am using 2 printers.
1. A network Printer which is of HP
2. Amyuni PDF converter to convert the reports to PDF format if the user selects that option.

The problem is for some reason, even when the user selects Paper mode( that is report to be printed on the network printer), the Amyuni PDF Converter is activated and no reports are printed. I used the getprinter() method to get the printer of the user and also usign set printer to name .... Still it is not working.
Is there a way I can get the Windows default printer and set it as the VFP default printer?

Thanks and Regards
FoxLearner
 
FoxLearner

A couple of things to try:
[ol][li] Try using the old:
Code:
lcPrinter=GETPRINTER()
SET PRINTER TO
SET PRINTER TO && Yes use it twice, its not a typo
SET PRINTER TO NAME "&lcPrinter" &&use macro sub INTO quotes
REPORT FORM formname TO PRINTER
[/LI]
[LI] You may also want to try Ramani's suggestion in FAQ184-581[/LI]
[LI] As a last resort try the suggestion in faq184-2444 to change the default windows printer via and API call[/li]
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Have you tried the SetDefaultPrinter() function in the ADVAPI.DRV?

Here is how it works.
Code:
LOCAL lcOldPrinter as String, lcNewPrinter as String
DECLARE integer SetDefaultPrinter in ADVAPI.DRV String
lcOldPrinter = set("Printer",2)
lcNewPrinter = getprinter()
SetDefaultPrinter(lcNewPrinter)

Not really difficult

Boudewijn[wavey3]
 
FoxLearner

Another alternative :-

'How to change default Windows printer with 2 lines of code ' faq184-2747
FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
Baldwin

DECLARE integer SetDefaultPrinter in ADVAPI.DRV String

Have you actually tried this? VFP7.0, Win'98, throws an error. ADVAPI.DRV isn't that a win3.x DLL?
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
FoxLearner

Another two liner to change the default printer woudl be:
Code:
oNet = CREATEOBJECT("WScript.Network")
oNet.SetDefaultPrinter("\\slp_nt_termserv\Panasonic Printer")

P.S. It also works on loacal printers. And assumes that "Windows Scripting" is installed on the computer.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,

You wrote:
"DECLARE integer SetDefaultPrinter in ADVAPI.DRV String

Have you actually tried this? VFP7.0, Win'98, throws an error. ADVAPI.DRV isn't that a win3.x DLL?"

[hammer]

It ain't win3x. you're right though that this isn't working on win9x machines, you should read the system.ini there for the default printer. Very likely scripting will work there. Haven't tried it out myself yet.

Boudewijn
 
Boudewyn

It ain't win3x. you're right though that this isn't working on win9x machines, you should read the system.ini there for the default printer. Very likely scripting will work there. Haven't tried it out myself yet.

My original question was to Baldwin (or are you and Baldwin the same person?), and it was only to point out to Foxlearner that Baldwin's suggestion might not work.

you should read the system.ini there for the default printer.

You may want to offer the suggestion to the person who posted the question.
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
The code "DECLARE integer SetDefaultPrinter in ADVAPI.DRV String" doesn't work in Win2k either;

it appears that ".DRV" is a typo..
ADVAPI.DLL seems to have been a 16bit DLL that was part of Win3.x
And was replaced by ADVAPI32.DLL in Win98/2k/etc. I found "thunking" code samples showing how to redirect calls from AdvApi.dll to AdvApi32.dll when rebuilding C++ programs to run under win98/2k.

The docs (MSDN) say that SetDefaultPrinter is new in Win2k, that the SYSTEM.INI (or more specificially, "To set the default printer to earlier operating systems, call GetProfileString, WriteProfileString, and SendNotifyMessage, as shown in the following code:") controls the default printer in WinME and earlier)

here's that code:
Code:
GetProfileString(TEXT("Windows"),TEXT("Device"),_T(",,,"),m_szName, COUNTOF(m_szName));
WriteProfileString(TEXT("Windows"),TEXT("Device"),pszPrinterName ));
        // Notify all open applications of the change. Note, only applications that handle the message will recognize the change.
#if WM_WININICHANGE != WM_SETTINGCHANGE
        // Old message type; for windows95
SendNotifyMessage(HWND_BROADCAST,WM_WININICHANGE,0,(LPARAM)szWindows);
#endif
        // New message type
SendNotifyMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,(LPARAM)szWindows);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top