Article ID: 105662
Article Last Modified on 5/6/2003
'-------------------------------------------------------------------
'Declarations Section
'-------------------------------------------------------------------
Option Compare Database 'Use database order for string comparisons
Option Explicit
Type DOCINFO
cbSize As Integer
lpszDocname As Long
lpszOutPut As Long
End Type
Declare Function GetProfileString% Lib "Kernel" (ByVal lpAppName$, _
ByVal lpkeyname$, ByVal lpDefault$, _
ByVal lpReturnedString$, ByVal nsize%)
Declare Function CreateDC% Lib "GDI" (ByVal lpDriverName$, _
ByVal lpDeviceName$, ByVal lpOutput$, _
lpInitData As Any)
Declare Function DeleteDC% Lib "GDI" (ByVal hDC%)
Declare Function TextOut% Lib "GDI" (ByVal hDC%, ByVal X%, ByVal _
Y%, ByVal lpString$, ByVal nCount%)
Declare Function Mylstrcpy& Lib "Kernel" Alias "lstrcpy" ( _
ByVal lpString1 As Any, ByVal lpString2 As Any)
Declare Function StartDoc% Lib "GDI" (ByVal hDC%, lpdi As DOCINFO)
Declare Function StartPage% Lib "GDI" (ByVal hDC%)
Declare Function EndPage% Lib "GDI" (ByVal hDC%)
Declare Function EndDocAPI% Lib "GDI" Alias "EndDoc" (ByVal hDC%)
Declare Function Rectangle% Lib "GDI" (ByVal hDC%, ByVal X1%, _
ByVal Y1%, ByVal X2%, ByVal Y2%)
'-------------------------------------------------------------------
'Start of Function
'-------------------------------------------------------------------
Function Printer ()
Dim lpReturnedString$
Dim MyDoc As DOCINFO
Dim MyDocumentname$
Dim nPrinter, nDriver, nDevice
Dim szDevice, szDriver, szOutPut
Dim hDC%, X%, MyString$
MyDocumentname$ = "My Document"
'------------------------------------------
' Retrieve the currently selected printer as
' establish with the Control panel.
' Sample string as returned by lpReturnedString$:
'
' HP LaserJet IIISi PostScript,pscript,LPT1:
'------------------------------------------
lpReturnedString$ = Space$(128)
nPrinter = GetProfileString("windows", "device", ",,,", _
lpReturnedString$, Len(lpReturnedString$))
'-----------------------------------------
' Parse the string of its three components
'-----------------------------------------
nDevice = InStr(lpReturnedString$, ",")
nDriver = InStr(nDevice + 2, lpReturnedString$, ",")
szDevice = Mid$(lpReturnedString$, 1, nDevice - 1)
szDriver = Mid$(lpReturnedString$, nDevice + 1, nDriver - _
nDevice - 1)
szOutPut = Mid$(lpReturnedString$, nDriver + 1)
'------------------------------------------
' Create the DOCINFO structure for StartDoc()
' - lpszDocname is name displayed in PRINTMAN
' - lpszOutPut is not used and set to NULL
'------------------------------------------
MyDoc.cbSize = Len(MyDoc)
MyDoc.lpszDocname = Mylstrcpy(MyDocumentname$, MyDocumentname$)
MyDoc.lpszOutPut = 0&
'------------------------------------------
' Create the device context
'------------------------------------------
hDC% = CreateDC(szDriver, szDevice, szOutPut, 0&)
X% = StartDoc(hDC%, MyDoc)
X% = StartPage(hDC%)
'------------------------------------------
' Rectangle arguments are X, Y, cX, cY
'------------------------------------------
X% = Rectangle(hDC%, 10, 10, 1000, 150)
MyString$ = "Derek and Robyn are brother and sister!"
'------------------------------------------
' Second and third arguments are the X and Y
' coordinates on paper.
'------------------------------------------
X% = TextOut(hDC%, 30, 20, MyString$, Len(MyString$))
X% = EndPage(hDC%)
X% = EndDocAPI(hDC%)
'------------------------------------------
' Release the device context when done
'------------------------------------------
hDC% = DeleteDC(hDC%)
End Function
'-------------------------------------------------------------------
'End of Function
'-------------------------------------------------------------------
Keywords: kbhowto kbprint KB105662