
Print directly to the printer
I don't imagine that this is actually of any use, but in case anyone
is interested, this is 'old style' windows printing:
---------------------------------------------
Option Compare Database
Option Explicit
'00/12/04 dlg from KB Q105662 not in use
Option Private Module
Const mcModuleName = "mdlRP_PrintText"
Private 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%)
Private Declare Function PTM_apiCreateDC Lib "Gdi32" Alias "CreateDCA" (ByVal lpDriverName$, _
ByVal lpDeviceName$, ByVal lpOutput$, _
lpInitData As Any) As Long
Private Declare Function PTM_apiDeleteDC Lib "Gdi32" Alias "DeleteDC" (ByVal hDC&) As Long
Private Declare Function PTM_apiTextOut Lib "Gdi32" Alias "TextOutA" (ByVal hDC&, ByVal x&, ByVal _
y&, ByVal lpString$, ByVal nCount&) As Long
Private Declare Function Mylstrcpy& Lib "Kernel32" Alias "lstrcpy" ( _
ByVal lpString1 As Any, ByVal lpString2 As Any)
Private Declare Function PTM_apiStartDoc Lib "Gdi32" Alias "StartDocA" (ByVal hDC&, lpdi As DOCINFO) As Long
Private Declare Function PTM_apiStartPage Lib "Gdi32" Alias "StartPage" (ByVal hDC&) As Long
Private Declare Function PTM_apiEndPage Lib "Gdi32" Alias "EndPage" (ByVal hDC&) As Long
Private Declare Function PTM_apiEndDoc Lib "Gdi32" Alias "EndDoc" (ByVal hDC&) As Long
Private Declare Function PTM_apiRectangle Lib "Gdi32" Alias "Rectangle" (ByVal hDC&, ByVal X1&, _
ByVal Y1&, ByVal X2&, ByVal Y2&) As Long
'-------------------------------------------------------------------
'Start of Function
'-------------------------------------------------------------------
Sub gsbRP_Printer(MyString$)
'00/12/04 dlg from KB Q105662 not in use
Dim lpReturnedString$
Dim MyDoc As DOCINFO
Dim MyDocumentname$
Dim nPrinter, nDriver, nDevice
Dim szDevice, szDriver, szOutPut
Dim hDC&, x&
MyDocumentname$ = "CTM"
'------------------------------------------
' 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 = PTM_apiGetProfileString("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& = PTM_apiCreateDC(szDriver, szDevice, szOutPut, 0&)
x& = PTM_apiStartDoc(hDC&, MyDoc)
x& = PTM_apiStartPage(hDC&)
'------------------------------------------
' Rectangle arguments are X, Y, cX, cY
'------------------------------------------
'X& = PTM_apiRectangle(hDC&, 10, 10, 1000, 150)
'------------------------------------------
' Second and third arguments are the X and Y
' coordinates on paper.
'------------------------------------------
x& = PTM_apiTextOut(hDC&, 30, 20, MyString$, Len(MyString$))
x& = PTM_apiEndPage(hDC&)
x& = PTM_apiEndDoc(hDC&)
'------------------------------------------
' Release the device context when done
'------------------------------------------
hDC& = PTM_apiDeleteDC(hDC&)
End Sub