/* PaperSize.prg Posted by Rick Miller (and more recently by Lyndon Sidelinger) in the dBASE newsgroups, originally written by Jim Sare. October 11, 2017 This program will return the paperName and paperSize 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:PaperSize 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:PaperSize with cPrinter Includes: getPapers() getPrinterDefault() */ #define DC_PAPERNAMES 16 #define DC_PAPERS 2 #define ZEROS(n) replicate(chr(0), n) parameters cDevice initExterns() if not type("argVector(1)") == "C" cDevice := getPrinterDefault() ? cDevice endif local a, i a = getPapers( 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 sizes for a printerName. // column 1 = paperName , // column 2 = paperSize . function getPapers(cDevice, cPort) local aRet, cName, i, ii, lpDevMode, nPair, nWord,; sPaperName, sPaperSize lpDevMode = 0 // get the number of paperSize/paperName pairs. nPair = RMM_DeviceCapability(; cDevice,; cPort,; DC_PAPERS,; null,; lpDevMode) if nPair > 0 // create empty paperSize buffer of proper length. sPaperSize = ZEROS(nPair * 2) // fill the paperSize buffer. RMM_DeviceCapability(; cDevice,; cPort,; DC_PAPERS,; sPaperSize,; lpDevMode) // create empty paperName buffer of proper length. sPaperName = ZEROS(nPair * 64) // fill the paperName buffer. RMM_DeviceCapability(; cDevice,; cPort,; DC_PAPERNAMES,; 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 paperSize number into nX. nWord = getWord(sPaperSize, 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 // paperSize. 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: PaperSize.prg