Printer selection

Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Printer selection

Post by Marc Vanzegbroeck »

Hi,

I'am still using FW1.9.5. In this version the TO clause doesn't work. I saw in the printer.prg source that it's looking at the WIN.INI file, and the printer aren't there in XP.
Is there a work-around? Is there maybe a function so I can change the default printer?

Thanks,
Marc
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Printer selection

Post by Enrico Maria Giordano »

It's time to upgrade to 32 bit. Anyway, this is a working function:

Code: Select all

function SetPrintDefault( cModel )

   local cDriver := StrToken( GetProfString( "Devices", cModel, "" ), 1, "," )
   local cPort   := StrToken( GetProfString( "Devices", cModel, "" ), 2, "," )

   WriteProfString( "Windows", "Device", cModel + ",", + cDriver + "," + cPort )

return nil
EMG
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Post by Marc Vanzegbroeck »

Thanks, I now I have to move to 32bits, but this application is still in 16 :cry:

It's working, but the problem stays.
As I already experience before. If I start the application, then change the defaultprinter, he program still print to to default printer as it was wen starting the program. I there a solution for this problem?

Thanks,
Marc
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

Marc Vanzegbroeck wrote:It's working, but the problem stays.
As I already experience before. If I start the application, then change the defaultprinter, he program still print to to default printer as it was wen starting the program.
It should not. The following sample works fine for me in 16 bit:

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oPrn, oFnt

    LOCAL nHStep, nVStep

    SETPRINTDEFAULT( "Win2PDF" )

    PRINT oPrn PREVIEW
        DEFINE FONT oFnt  NAME "Arial" SIZE 0, -10 OF oPrn

        nHStep = oPrn:nHorzRes() / 80
        nVStep = oPrn:nVertRes() / 66

        PAGE
            oPrn:Say( 0, 0, "This is a test", oFnt )
            oPrn:Say( 1 * nVStep, 0, "This is a test", oFnt )
        ENDPAGE
    ENDPRINT

    RELEASE FONT oFnt

    RETURN NIL


function SetPrintDefault( cModel ) 

   local cDriver := StrToken( GetProfString( "Devices", cModel, "" ), 1, "," ) 
   local cPort   := StrToken( GetProfString( "Devices", cModel, "" ), 2, "," ) 

   WriteProfString( "Windows", "Device", cModel + ",", + cDriver + "," + cPort ) 

return nil
EMG
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Post by Marc Vanzegbroeck »

The SETPRINTDEFAULT() change the defaultprinter but print to the default printer as it was before.
Closing the program and restarting, it print to the correct printer.
Maybe it was an error in FW1.9.5 :cry:
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

Check if SetPrintDefault() really changes your default printer. If yes, your print have to necessarily go to that printer. Unless you issued SetPrintDefault() after PRINT command.

Did you try my sample as it is (changing the printer, of course)? Are you sure that the printer name you provided was correct? Copy and paste it from printers control panel just to be sure.

EMG
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Post by Marc Vanzegbroeck »

Enrico,

SetPrintDefault() really change my defaultprinter. This is not the problem. As I already told in my previous message. If I launch the program, than change the default printer manualy (via printer configuration) and than print, the program print to the printer that was the default one BEFORE launching my program. So the SetPrintDefault() have also no effect.

Marc
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

This is not what I get. How can TPrinter print on a printer that is not selected as default printer at the time you issue the PRINT command?

EMG
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Post by Marc Vanzegbroeck »

I know it sound strange, but I just doublechecked it in an other FW-application I wrote, and it's just the same.. :(
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Marc,

>SetPrintDefault() really change my defaultprinter. This is not the problem. As I already told in my previous message. If I launch the program, than change the default printer manualy (via printer configuration) and than print, the program print to the printer that was the default one BEFORE launching my program. So the SetPrintDefault() have also no effect.<

When you say, "change the default printer manually (via the printer configuration" do you mean via the Windows Control Panel? If so, that is the way things are supposed to work. The same would be true if you called SetPrintDefault() from within the program--I expect. I have not used it, but I presume it is changing the Windows default printer.

When an app runs it picks up the current Windows default printer as defined in the Windows Control Panel. That printer is now the application's default printer until or unless it is changed from within the application. You can do this via the setPrinter() function which calls up the Windows common control to set the printer. This function is normally called from the File-Printer Setup menu. Note that this function only changes the application's printer not the Windows default printer.

Changing the Windows default printer from the Control Panel while a application is running will not change the application's current default printer. The application will pick up that printer the next time it is run, however.

Note: I suggest that you should never change the Windows default printer from within an application. This will probably confuse and irritate the user. If you have a need to default your application to the same printer each time it is run, you can get code to do this on my website on this page. I have not tested it under 16bit however. Look under the Downloads section for "Saving and restoring the application's printer."

http://ourworld.compuserve.com/homepage ... rogram.htm

I hope that helps.

James
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

This is not the behavior I observe in my tests. Did you try my sample? It prints to the new default printer, not to the old one. At least in 32 bit under Windows XP.

EMG
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Post by Marc Vanzegbroeck »

James,
It's working!!! Thanks.

Enrico,
Maybe it's an 16 bit behavior that the program take the default printer at program startup...

Marc
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

No, sorry, I just tested it in 16 bit and the behavior is exactly the same as in 32 bit: it prints on the new default printer.

EMG
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Enrico,

>This is not the behavior I observe in my tests. Did you try my sample? It prints to the new default printer, not to the old one.

As I said in my previous message, I hadn't tried your code. I just did, and surprisingly it does print to the new Windows default printer. It doesn't seem logical that it would. I just tried running an application, then changing the default printer via the Windows Control Panel and the application's default printer remains that same as it was.

Apparently, your code is triggering a notification to the application to change it's printer but Windows' setup doesn't. Very odd.

As I mentioned in my previous message I highly recommend against changing the Windows default printer from within an application. Users are not going to expect this and it will probably upset them. Personally, I would be upset if a program did this.

James
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

James Bott wrote:As I mentioned in my previous message I highly recommend against changing the Windows default printer from within an application. Users are not going to expect this and it will probably upset them. Personally, I would be upset if a program did this.
I strongly agree. It was only a possible workaround, a fast and dirty solution of the Marc problem.

EMG
Post Reply