Anyone know of a routine that can give the equivalent of SET("PRINTER", 3) in VFP 5.0? I've got to retrofit some working 6.0 / 7.0 code back into a 5.0 application. <s>
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
I thought of that one to, but it doesn't give Rick the "Default Visual FoxPro printer nameDefault Visual FoxPro printer name" 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.
You can adapt the following code to return the name of the system printer. It is from a class, so "this.SystemPrinter" 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 = "windows" + chr(0)
lpKeyName = "device" + 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(",",lpReturnedString)-1)
lResult = .T.
else
#ifdef _DEBUG
messageBox("GetProfileString() returned 0 in GetSystemPrinter()",48,"Function Error"
#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
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.
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
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("PRINTER", 3). It appears only VFP knows the current VFP printer.
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 "regular" basis that would not distress the user with "flashing" windows.
This does not solve Rick's problem, but might be useful to someone.
! /N SetDefPr "WinFax"
will set the Windows default printer without showing a DOS box
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 "clear vision" to pull it off.
*Function SetPrinter3()
* Duplicates the VFP 6.0 & 7.0
* SET("Printer", 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 + ".FRX"
lnLine = Atline("DEVICE=", Expr)
lcStr = Mline(Expr, lnLine)
lcPrinterName = Substr( lcStr, At("=", lcStr )+1)
USE IN (lcReportName)
ERASE (lcReportName + ".FRX"
ERASE (lcReportName + ".FRT"
IF !EMPTY(lcAlias)
SELECT (lcAlias)
ENDIF
RETURN UPPER(lcPrinterName)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.