Subject |
Re: printer paper source |
From |
Mervyn Bick <invalid@invalid.invalid> |
Date |
Sun, 9 Aug 2020 10:33:34 +0200 |
Newsgroups |
dbase.getting-started |
Attachment(s) |
paperbin.prg |
On 2020-08-09 06:37, Ken Mayer wrote:
> Thanks, Rich. Did a search through misc code in the dUFLP hoping maybe
> something was there, but ...
I took Rick Millers PaperSize.prg in the dUFLP and made the necessary
changes to it so as to retrieve the available paper bins.
It works but it has only been tested on my little Canon printer because
that's the only one available.
This should sort out Mustansir's problem and you may want to include it
in the dUFLP.
Mervyn.
| /*
PaperBin.prg
This a direct copy of PapeSize.prg posted by Rick Miller with the necessary
changes so as to be able to identify the available paper sources.
2020-08-09
This program will return the binName and PapeBin information
for the default printer. The number returned for each option
could then be used for a report. This is really not a production
program, but meant to be used by a developer to help as needed.
Output is to the output pane of the Command Window.
Usage:
do :dUFLP:PapeBin
or to use a printer other than the default, you would need
to know the name of the printer:
cPrinter = "HP LaserJet 1020"
do :dUFLP:PapeBin with cPrinter
Includes:
getBins()
getPrinterDefault()
*/
#define DC_PAPERNAMES 16
#define DC_PAPERS 2
#define DC_BINNAMES 12
#define DC_BINS 6
#define ZEROS(n) replicate(chr(0), n)
parameters cDevice
initExterns()
if not type("argVector(1)") == "C"
cDevice := getPrinterDefault()
? cDevice
endif
local a, i
a = getBins( cDevice, "")
for i = 1 to int((a.size + 1) / 2)
? a[i, 2]
?? " - "
?? a[i, 1]
endfor
return
//------------------------------------------------------------//
// return a 2 column array of paper bins for a printerName.
// column 1 = paperName <char>,
// column 2 = PapeBin <int>.
function getBins(cDevice, cPort)
local aRet, cName, i, ii, lpDevMode, nPair, nWord,;
sPaperName, sPapeBin
lpDevMode = 0
// get the number of PapeBin/paperName pairs.
nPair = RMM_DeviceCapability(;
cDevice,;
cPort,;
DC_BINS,;
null,;
lpDevMode)
if nPair > 0
// create empty PapeBin buffer of proper length.
sPapeBin = ZEROS(nPair * 2)
// fill the PapeBin buffer.
RMM_DeviceCapability(;
cDevice,;
cPort,;
DC_BINS,;
sPapeBin,;
lpDevMode)
// create empty paperName buffer of proper length.
sPaperName = ZEROS(nPair * 64)
// fill the paperName buffer.
RMM_DeviceCapability(;
cDevice,;
cPort,;
DC_BINNAMES,;
sPaperName,;
lpDevMode)
// create the return array.
aRet = new array(nPair, 2)
for i = 0 to nPair - 1
// loop through and assign the array values.
// store the PapeBin number into nX.
nWord = getWord(sPapeBin, i * 2)
cName = ""
for ii = 0 to 63
// loop through reading the paperName buffer.
if sPaperName.getByte((i * 64) + ii) == 0
// ran into a string terminator.
// assign ii to exit the loop.
ii := 64
else
// add the character to c.
cName += chr(sPaperName.getByte( ;
(i * 64) + ii))
endif
endfor
// assign the pair to a row in the array.
aRet[i + 1, 1] = cName // paperName.
aRet[i + 1, 2] = nWord // PapeBin.
endfor
else
aRet = new array()
endif
return aRet
//------------------------------------------------------------//
// return the windows default printer as a string.
function getPrinterDefault
Local sBuff, cRet, nLen
sBuff = ZEROS(250)
nLen = RMM_GetWinIniString( ;
"windows", "device", ;
",,,", sBuff, sBuff.length)
cRet = sBuff.left(sBuff.indexOf(","))
return cRet.rightTrim()
//------------------------------------------------------------//
// return a WORD from the string sValu starting at nByte.
function getWord(sValu, nByte)
return int(sValu.getByte(nByte) + ;
bitlshift(sValu.getByte(nByte + 1), 8))
//------------------------------------------------------------//
function initExterns
if not type("RMM_DeviceCapability") == "FP"
extern CINT RMM_DeviceCapability( ;
CSTRING, CSTRING, CWORD, CPTR, CPTR);
winspool.drv from 'DeviceCapabilitiesA'
endif
if not type("RMM_GetWinIniString") == "FP"
extern CULONG RMM_GetWinIniString( ;
CSTRING, CSTRING, CSTRING, CSTRING, CULONG);
kernel32 from "GetProfileStringA"
endif
return
// end of file: PapeBin.prg
|
|