* Start of Code
*!* Declare the CreateDC function
DECLARE LONG CreateDC IN gdi32.DLL ;
STRING @cDriver, STRING @cDevice, STRING cOutput, ;
STRING cInitData
*!* Declare the DeleteDC function
DECLARE LONG DeleteDC IN gdi32.DLL ;
LONG nDC
*!* Declare the TextOut function
DECLARE INTEGER TextOut IN gdi32.DLL INTEGER hDC, INTEGER xStart, INTEGER yStart, ;
STRING @PrintString, INTEGER cbString
*!* Declare the StartDoc function
DECLARE INTEGER StartDoc IN gdi32.DLL INTEGER hDC, STRING @DocInfo
*!* Declare the StartPage function
DECLARE INTEGER StartPage IN gdi32.DLL INTEGER hDC
*!* Declare the EndPage function
DECLARE INTEGER EndPage IN gdi32.DLL INTEGER hDC
*!* Declare the EndDoc function
DECLARE INTEGER EndDoc IN gdi32.DLL INTEGER hDC
*!* Declare the GetLastError function
DECLARE INTEGER GetLastError IN kernel32.DLL
*!* Allocate a buffer
lcBuffer = SPACE(255)
IF "5.0"$OS()
*!* If the OS is 5.0, the driver is either DISPLAY or WINSPOOL
lcDriver="WINSPOOL"
ELSE
*!* If the OS is Windows 9x, the driver is NULL
lcDriver=NULL
ENDIF
*!* Get the name of the printer for which we want an HDC
lcPrinter=GETPRINTER()
hDC = CreateDC(lcDriver, lcPrinter, NULL, NULL)
IF hDC = 0
MESSAGEBOX("Unable to create device context" + CHR(13) + ;
"Error Code : " + ALLTRIM(STR(GetLastError())),48)
RETURN
ENDIF
*!* Create a DOCINFO structure to pass to StartDoc
lcDocInfo = Long2Str(20) + REPLICATE(CHR(0), 16)
*!* Call StartDoc()
retCode = StartDoc(hDC, @lcDocInfo)
IF retCode <= 0
MESSAGEBOX("Error calling StartDoc" + CHR(13) + ;
" Error code : " + ALLTRIM(STR(GetLastError())),48)
RETURN
ENDIF
*!* Call StartPage()
retCode = StartPage(hDC)
IF retCode <= 0
MESSAGEBOX("Error calling StartPage" + CHR(13) + ;
" Error code : " + ALLTRIM(STR(GetLastError())),48)
RETURN
ENDIF
*!* Define a string to send to the print device
myString = "Using API functions for printing"
myLength = LEN(myString)
*!* Call TextOut, first parameter is the device context handle
*!* second parameter is x coordinate
*!* third parameter is y coordinate
*!* fourth parameter is the string, which is passed by reference
*!* fifth parameter is the length of the string being passed
retCode = TextOut(hDC, 10, 10, @myString, myLength)
IF retCode <= 0
MESSAGEBOX("Error calling TextOut" + CHR(13) + ;
" Error code : " + ALLTRIM(STR(GetLastError())),48)
RETURN
ENDIF
*!* Done printing a page, so call EndPage()
retCode = EndPage(hDC)
IF retCode <= 0
MESSAGEBOX("Error calling EndPage" + CHR(13) + ;
" Error code : " + ALLTRIM(STR(GetLastError())),48)
RETURN
ENDIF
*!* Done printing a document, so call EndDoc()
retCode = EndDoc(hDC)
IF retCode <= 0
MESSAGEBOX("Error calling EndDoc" + CHR(13) + ;
" Error code : " + ALLTRIM(STR(GetLastError())),48)
RETURN
ENDIF
*!* Clear the DLLs from memory
CLEAR DLLS
FUNCTION Long2Str
PARAMETERS m.longval
PRIVATE i, m.retstr
m.retstr = ""
FOR i = 24 TO 0 STEP -8
m.retstr = CHR(INT(m.longval/(2^i))) + m.retstr
m.longval = MOD(m.longval, (2^i))
NEXT
RETURN m.retstr
* End of Code