/* This sample program can be used to Add, Change or Delete printer forms. */ #INCLUDE "dcdialog.CH" #INCLUDE "dll.CH" #INCLUDE "bap.CH" #INCLUDE "appevent.CH" #define FORM_USER 0 #define FORM_BUILTIN 1 #define FORM_PRINTER 2 #Pragma Library("BAP.LIB") STATIC snHdll FUNCTION Main() LOCAL cPrinterName, cFormName, GetList[0], oPrinter, cPrinter, nChoice := 1 , ; aList, aPrinters[0], aForms[0], oBrowsePrinters, oBrowseForms, ; nPrinter := 1, nForm := 1, i, GetOptions, nCol := 1, oFormSay cPrinterName := '' cFormName := '' aList := XbpPrinter():new():list() FOR i := 1 TO Len(aList) AAdd(aPrinters,{aList[i]}) NEXT ASort( aPrinters,,,{|a,b|a[1] 0 PostAppEvent(xbeBRW_ItemMarked,.t.,,oBrowsePrinters) ENDIF ENDIF RETURN nil * ----------- FUNCTION SizeStructure( nWidth, nHeight ) LOCAL aBin := BaInit(2), cBin BaStruct( aBin, nWidth ) // Width BaStruct( aBin, nHeight ) // height cBin := BaAccess(aBin) RETURN cBin * ----------- FUNCTION RectStructure( nLeft, nTop, nRight, nBottom ) LOCAL aBin := BaInit(4), cBin BaStruct( aBin, nLeft ) // left BaStruct( aBin, nTop ) // top BaStruct( aBin, nRight ) // right BaStruct( aBin, nBottom ) // bottom cBin := BaAccess(aBin) RETURN cBin * ----------- FUNCTION FormStructure( nFlags, cFormName, sSize, sRect ) LOCAL aBin := BaInit(4), cBin cFormName := cFormName BaStruct( aBin, nFlags ) // Flags BaStruct( aBin, @cFormName ) // Name BaStruct( aBin, sSize ) // SIZEL BaStruct( aBin, sRect ) // RECTL cBin := BaAccess(aBin) RETURN cBin * ------------- FUNCTION PrinterForm( nAction, cPrinterName, cFormName, nWidth, nHeight ) LOCAL sSize, sRect, nFlags, nPrinter, hPrinter := 0, sForm, nLevel := 1, ; nStatus sSize := SizeStructure( nWidth, nHeight ) sRect := RectStructure( 0, 0, nWidth, nHeight ) nFlags := FORM_USER sForm := FormStructure( nFlags, @cFormName, @sSize, @sRect ) nPrinter := OpenPrinterA( cPrinterName, @hPrinter, nil ) IF hPrinter > 0 IF nAction == 1 nStatus := AddFormA( hPrinter, nLevel, @sForm ) ELSEIF nAction == 2 nStatus := SetFormA( hPrinter, cFormName, nLevel, @sForm ) ELSEIF nAction == 3 nStatus := DeleteFormA( hPrinter, cFormName ) ENDIF ELSE nStatus := -1 ENDIF IF nStatus > 0 DCMSGBOX 'Success!!' ELSEIF nStatus == -1 DCMSGBOX 'Failed. Printer not Found!!' ELSE DCMSGBOX 'Failed. Reason unknown!!' ENDIF ClosePrinter( hPrinter ) RETURN nStatus * ---------- DLLFUNCTION AddFormA( hPrinter, nLevel, sForm ) USING STDCALL FROM WINSPOOL.DRV DLLFUNCTION OpenPrinterA( cPrinterName, @hPrinter, sDefaults ) USING STDCALL FROM WINSPOOL.DRV DLLFUNCTION ClosePrinter( hPrinter ) USING STDCALL FROM WINSPOOL.DRV DLLFUNCTION SetFormA( hPrinter, cFormName, nLevel, sForm ) USING STDCALL FROM WINSPOOL.DRV DLLFUNCTION GetLastError() USING STDCALL FROM KERNEL32.DLL DLLFUNCTION DeleteFormA( hPrinter, cFormName ) USING STDCALL FROM WINSPOOL.DRV