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

Current Printer - VFP 5.0

Status
Not open for further replies.

rgbean

Programmer
Nov 9, 2000
5,707
US
Anyone know of a routine that can give the equivalent of SET(&quot;PRINTER&quot;, 3) in VFP 5.0? I've got to retrofit some working 6.0 / 7.0 code back into a 5.0 application. <s>

Rick
 
The only way I found to do this is:
Code:
LOCAL lcDefaultPrinter
SET PRINTER TO DEFAULT
lcDefaultPrinter = SYS(6)

 
This doesn't seem to return anything in VFP 5.0 under XP Pro OR Win 98 SE - for DEFAULT OR NAME printers (local or networked).

Rick
 
HI Rick,
Does APRINTERS() help in VFP5. Sorry that I dont have VFP5 any longer and have no way to check it. What I mean is to use APRINTERS() and create a routine to extract some thing to achieve what you want. For a man of your abilities, suggesting something like APRINTERS(), I feel dumb.
I would be happy if I could be of some help to you :)
ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Ramani,

I thought of that one to, but it doesn't give Rick the &quot;Default Visual FoxPro printer nameDefault Visual FoxPro printer name&quot; it just list them all. And I tested it, no matter what Windows default printer is set, the order doesn't change.
 
Thanks anyway guys, well at least I haven't overlooked something obvious. <g> I guess I'm going to have to dig into the WinAPI - I'm sure I can find it somewhere in there, I just avoid this kind of solution whenever possible.

Rick
 
Anyway Default Printer name in VFP7 can be obtained..

myDefaultWinPrinter = SET(&quot;PRINTER&quot;,2)
myDefaultVFP7Printer = SET(&quot;PRINTER&quot;,3)

VFP5.. I dont know off my head.
:) :) :) ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Ramani,
That's the problem, SET(&quot;PRINTER&quot;,3) was introduced in VFP 6.0, and I need the equivalent functionality in VFP 5.0.

Rick
 
You can adapt the following code to return the name of the system printer. It is from a class, so &quot;this.SystemPrinter&quot; will have to be changed to your output. Tested on Win98, NT4, and 2000Pro.

declare integer GetProfileString in Win32API ;
string @lpAppName,; && address of section name
string @lpKeyName,; && address of key name
string @lpDefault,; && address of default string
string @lpReturnedString,; && address of destination buffer
integer nSize && size of destination buffer



Function GetSystemPrinter()
local lpAppName,lpKeyName,lpDefault,lpReturnedString,nSize,lResult
lResult = .F.

lpAppName = &quot;windows&quot; + chr(0)
lpKeyName = &quot;device&quot; + chr(0)
lpDefault = chr(0)
store space(1024) to lpReturnedString
nSize = len(lpReturnedString)

nResult = GetProfileString(@lpAppName,@lpKeyName,@lpDefault,@lpReturnedString,nSize)
if nResult > 0
this.SystemPrinter = substr(lpReturnedString,1,at(&quot;,&quot;,lpReturnedString)-1)
lResult = .T.
else
#ifdef _DEBUG
messageBox(&quot;GetProfileString() returned 0 in GetSystemPrinter()&quot;,48,&quot;Function Error&quot;)
#endif
endif
return lResult
 
The following functions are used to return a comma separated list of printers installed on the system. You should parse out the printer of interest since the name must be exact when set as the system printer. Watch the wrap.

Function GetPrinterList()
local lpAppName,lpKeyName,lpDefault,lpReturnedString,nSize,nResult

nResult = 0
lpAppName = &quot;PrinterPorts&quot; + chr(0)
lpKeyName = .null.
lpDefault = chr(0)
store space(2048) to lpReturnedString
nSize = len(lpReturnedString)

nResult = GetProfileString(@lpAppName,@lpKeyName,@lpDefault,@lpReturnedString,nSize)
if nResult > 0
cResult = this.StripNulls(substr(lpReturnedString,1,nResult-1))
else
#ifdef _DEBUG
messageBox(&quot;GetProfileString() returned 0 in GetPrinterList()&quot;,48,&quot;Function Error&quot;)
#endif
endif
return cResult

*--------------------------------
Function StripNulls(cBuffer)
local cTemp
cTemp = &quot;&quot;
for i = 1 to len(cBuffer)
if substr(cBuffer,i,1) = chr(0)
cTemp = cTemp + &quot;,&quot;
else
cTemp = cTemp + substr(cBuffer,i,1)
endif
endfor
if substr(cTemp,len(cTemp)-1,1) = &quot;,&quot;
cTemp = substr(cTemp,1,len(cTemp) - 1)
endif
return cTemp
 
And, finally, set the system printer. Broadcast the change to force windows to reload the registry or the change will have no immediate effect. As the function name indicates, this will not work on Win9x. I have another function for that if you need it. I hope you find this useful.


#define HWND_BROADCAST 0x0000FFFF
#define WM_WININICHANGE 0x0000001A

declare integer WriteProfileString in Win32API ;
string @lpszSection,; && pointer to section name
string @lpszKeyName,; && pointer to key name
string @lpszString && pointer to string to write

declare integer SendMessage in Win32API ;
integer hWnd,; && handle of destination window
integer wMsg,; && message to send
integer wParam,; && first message parameter
string lParam && second message parameter


Function SetDefaultPrinterNT(cPrinterName)
local lpAppName,lpKeyName,lpDefault,lpReturnedString,nSize,nResult,cPrinterDriver,cPrinterPort,cLine,lResult

lResult = .F.
lpAppName = &quot;PrinterPorts&quot; + chr(0)
lpKeyName = cPrinterName + chr(0)
lpDefault = &quot;Failed&quot; + chr(0)
store space(1024) to lpReturnedString
nSize = len(lpReturnedString)

nResult = GetProfileString(lpAppName,lpKeyName,lpDefault,lpReturnedString,nSize)
if nResult > 0
cPrinterDriver = substr(lpReturnedString,1,at(&quot;,&quot;,lpReturnedString)-1)
cPrinterPort = substr(lpReturnedString,at(&quot;,&quot;,lpReturnedString)+1,at(&quot;,&quot;,lpReturnedString,2)-1)
if not ((cPrinterDriver == &quot;&quot;) and (cPrinterPort == &quot;&quot;))
cLine = PrinterName + &quot;,&quot; + DriverName + &quot;,&quot; + PrinterPort
nResult = WriteProfileString(&quot;windows&quot;,&quot;device&quot;,cLine)
if nResult <> 0
nResult = SendMessage(HWND_BROADCAST,WM_WININICHANGE,0,&quot;Windows&quot;)
lResult = .T.
else
#ifdef _DEBUG
messageBox(&quot;WriteProfileString returned 0 in SetDefaultPrinterNT()&quot;,48,&quot;Function Error&quot;)
#endif
endif
endif
else
#ifdef _DEBUG
messageBox(&quot;GetProfileString returned 0 in SetDefaultPrinterNT()&quot;,48,&quot;Function Error&quot;)
#endif
endif
return lResult
 
These are ALL wonderful routines (I used variants of them to solve problems in the past), but NONE of them will actually solve the original problem - a method to be used in VFP 5.0 that's the equivalent of VFP 6/7's SET(&quot;PRINTER&quot;, 3). It appears only VFP knows the current VFP printer.

Thanks for your attempts anyway.

Rick
 
Don't know if this would help or not. Could you create a dummy report, bail out at the last instant and then hack the report file to see what printer it used? Dave Dardinger
 
Dave,
Unfortunately you have to Modify or Create (and save) the report to get the current printer stored in the report's .FPT file. I couldn't think of any way to do this programatically on a &quot;regular&quot; basis that would not distress the user with &quot;flashing&quot; windows.

Rick
 
For all that may have be following this thread, I've got a working solution - Dave you and I were close, it just took someone with a &quot;clear vision&quot; to pull it off.

*Function SetPrinter3()
* Duplicates the VFP 6.0 & 7.0
* SET(&quot;Printer&quot;, 3) Functionality
* i.e. It returns the Current VFP printer
*
* Thanks to Sergey Berezniker on the UT - 4/13/2002
*
* ** RGB ** changed on 04/15/02 - Added saving ALIAS()
*
LOCAL LcCursorName, lcReportName, lnLine, lcPrinterName, ;
lcStr, lcAlias
lcAlias = ALIAS()
LcCursorName = Sys(2015)
lcReportName = Sys(2015)
SELECT 0
CREATE CURSOR (lcCursorName) ( temp C(1))
CREATE REPORT (lcReportName ) FROM (lcCursorName )
USE (lcReportName + &quot;.FRX&quot;)
lnLine = Atline(&quot;DEVICE=&quot;, Expr)
lcStr = Mline(Expr, lnLine)
lcPrinterName = Substr( lcStr, At(&quot;=&quot;, lcStr )+1)
USE IN (lcReportName)
ERASE (lcReportName + &quot;.FRX&quot;)
ERASE (lcReportName + &quot;.FRT&quot;)
IF !EMPTY(lcAlias)
SELECT (lcAlias)
ENDIF
RETURN UPPER(lcPrinterName)

*!* EOP: SETPRINTER3.PRG

Rick
 
I use this routine:
==========================
do case

case 'NT' $ os()
hdp=WSHShell.RegRead (&quot;HKEY_CURRENT_USER\software\microsoft\windows nt\currentversion\windows\device&quot;)
hdp=left(hdp,at(',',hdp)-1)

case '4.10' $ os() && Win98

hdp=WSHShell.RegRead(&quot;HKEY_LOCAL_MACHINE\config\0001\system\currentcontrolset\control\print\printers\default&quot;)

endcase
==============================

Or if that doesn't work: simply:

==============================
set printer to default
keyboard chr(13)
hdp=getprinter()
==============================
 
Sorry i missed 1 line:

Just before the Do case
WSHShell=CreateObject(&quot;WScript.Shell&quot;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top