Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Choosing a printer
Message
 
 
À
06/08/1999 02:28:37
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de rapports & Rapports
Divers
Thread ID:
00250441
Message ID:
00266190
Vues:
26
I figured out the trick, but not the solution. It doesn't change the printer until I exit SBT. I bet when it was working was when I was running it from VFP.

Thanks,

Michelle


>>I saw the SET PRINTER, but it seemed like a DOS holdover. I'll give it a shot.
>>
>
>
>The command is SET PRINTER TO NAME nameofprinter
>
>nameofprinter can be got from getprinter()
>
>This works SOMETIMES but not always. On NT machines especially this works very erratically if at all.
>
>What I do is get the name of the printer and call a function I have made called SETPRINTER(). This uses API's to write to the WIN.INI - Yes VFP does read from the win.ini where printer info is needed.
>
>So I just read the entry for the selected printer from the WIN.INI and write it out to the WIN.INI as the Current Default printer. Then another API to broadcast this change to all open apps.
>
>Code follows:
>FUNCTION setprntr
>PARAMETERS p_name
>* p_name is the name of the printer
>* This is set as the default
>IF EMPTY(p_name)
> RETURN
>ENDIF
>
>SET LIBRARY TO FOXTOOLS.fll ADDITIVE
>*aa=RegFn("GetWinIni","CCC@CI","I")
>aa=RegFn("GetProfileString","CCC@CI","I")
>ss=RegFn("SendMessage","IIIC","I")
>*ww=RegFn("WriteWinIni","CCC","I")
>ww=RegFn("WriteProfileString","CCC","I")
>fbuffer=SPACE(255)
>fsize=255
>fcat="PrinterPorts"
>fother=""
>bb=CallFn(aa,fcat,p_name,fother,@fbuffer,fsize)
>*bb=GetWinIni("PrinterPorts",p_name,"",@buffer,255)
>IF bb=0
> Wait window "Could not set the Default Printer to "+ALLTRIM(p_name)
> RELEASE LIBRARY FOXTOOLS.fll
> Return .F.
>ENDIF
>* got the driver and port string now parse it
>p_driver = substr(fbuffer,1,AT(",",fbuffer)-1)
>p_port = substr(fbuffer,AT(",",fbuffer)+1,AT(",",fbuffer,2)-AT(",",fbuffer)-1)
>p_line = p_name+","+p_driver+","+p_port
>* write it out
>bb=CallFn(ww,"windows","Device",p_line)
>*bb=WriteWinIni("windows","Device",p_line)
>IF bb=0
> Wait window "Could not set the Default Printer to "+ALLTRIM(p_name)
> RELEASE LIBRARY fxtool16.fll
> Return .F.
>ENDIF
>* broadcast it
>bb=CallFn(ss,65535,26,0,"windows")
>*bb= SendMessage(65535,26,0,"windows")
>
>IF bb=0
> Wait window "Could not set the Default Printer to "+ALLTRIM(p_name)
> RELEASE LIBRARY FOXTOOLS.fll
> Return .F.
>ELSE
>* wait window "Default Printer set to "+ALLTRIM(p_name)
>ENDIF
>
>RELEASE LIBRARY FOXTOOLS.fll
>RETURN
>* eof setprntr
>
>
>The commented out calls are for 16 bit fox
>
>Works every time
>
>Hope this helps
>
>Bernard
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform