Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get Printer information
Message
 
 
À
30/04/2007 09:02:53
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01220056
Message ID:
01221171
Vues:
12
>>>Can I adapt your code from the FAQ for the GdiPlusX library ?
>>>The image direct printing still needs some error checking, and your code fits all our needs for that.
>>
>>Hi Cesar,
>>
>>Sure, you can use it any way you want.

Looks like we have a problem again with UT and members from Brazil :(

Here is the intended message:
===========================================================================
Hi Sergey,

I wanted just for the records, to send the significant part of the code that retrieves the Paper size for the cases when PRTINFO(3 or 4) return -1

I've just incorporated it to the library, and I hope to publish a new version soon.

Thanks again for your valuable help !
LOCAL lnWidth, lnHeight, lcPrinter, lnPaperID
  lnWidth = 0
  lnHeight = 0
  lcPrinter = SET("Printer",3) && Default Printer
  lnPaperID = PRTINFO(2)

  =GetPaperDimensions(@lnWidth, @lnHeight, lnPaperID, lcPrinter)
  MESSAGEBOX(lcPrinter + CHR(13) + ;
   "Paper ID: " + TRANSFORM(lnPaperID) + CHR(13) + ;
   "Width: " + TRANSFORM(lnWidth) + CHR(13) + ;
   "Height: " + TRANSFORM(lnHeight), 64, "Paper Size Info")

  RETURN
FUNCTION GetPaperDimensions(tnWidth, tnHeight, tnPaperID, tcPrinter)

  * API declarations
  DECLARE INTEGER OpenPrinter IN winspool.drv STRING  @pPrinterName, INTEGER @phPrinter, INTEGER pDefault
  DECLARE INTEGER ClosePrinter IN winspool.drv INTEGER hPrinter
  DECLARE LONG EnumForms IN winspool.drv AS EnumForms LONG hPrinter, LONG Level, LONG pForm, LONG cbBuf, LONG @pcbNeeded, LONG @ pcReturned
  DECLARE INTEGER HeapCreate IN WIN32API INTEGER dwOptions, INTEGER dwInitialSize, INTEGER dwMaxSize
  DECLARE INTEGER HeapAlloc IN WIN32API INTEGER hHeap, INTEGER dwFlags, INTEGER dwBytes
  DECLARE INTEGER HeapFree IN WIN32API INTEGER hHeap, INTEGER dwFlags, INTEGER lpMem
  DECLARE HeapDestroy IN WIN32API INTEGER hHeap

  * Allocate a heap
  lhHeap = HeapCreate(0, 4096*10, 0)

  * Enumerate forms for default VFP printer
  LOCAL lhPrinter, lnNeeded, lnBuffer

  * Open a printer
  lhPrinter = 0
  lnResult = OpenPrinter(@tcPrinter, @lhPrinter, 0)

  * Get the size of the buffer required to fit all forms in lnNeeded
  lnNeeded = 0
  =EnumForms(lhPrinter, 1,  0, 0, @lnNeeded, 0)

  * Get the list of forms
  lnBuffer = HeapAlloc(lhHeap, 0, lnNeeded)
  =EnumForms(lhPrinter, 1, lnBuffer, @lnNeeded, @lnNeeded, 0)

  * Get the information for the desired Paper ID
  * The form attributes are stored in in thousandths of millimeters
  lnPointer = lnBuffer + (tnPaperID - 1) * 32
  tnWidth  = CTOBIN(SYS(2600, (lnPointer+ 8), 4),"4RS")
  tnHeight = CTOBIN(SYS(2600, (lnPointer+12), 4),"4RS")

  = HeapFree(lhHeap, 0, lnBuffer )
  = ClosePrinter(lhPrinter)

  * Clear the Heap
  IF lhHeap <> 0
   HeapDestroy(lhHeap)
  ENDIF

  RETURN
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform