Public Function PrintRTF(rtf As RichTextBox, nnLeftMarginWidth _
As Long, nnTopMarginHeight As Long, nnRightMarginWidth As _
Long, nnBottomMarginHeight As Long) As Boolean
' #VBIDEUtils#************************************************
' * Programmer Name : Waty Thierry
' * Web Site : [url]www.geocities.com/ResearchTriangle/6311/[/url]
' * Date : 30/10/98
' * Time : 14:43
' * Module Name : Main_Module
' * Module Filename : Main.bas
' * Procedure Name : PrintRTF
' * Parameters :
' * rtf As RichTextBox
' * nnLeftMarginWidth As Long
' * nnTopMarginHeight As Long
' * nnRightMarginWidth As Long
' * nnBottomMarginHeight As Long
' ***************************************************************
' * Comments :
' *
' *
' *************************************************************
On Error GoTo ErrorHandler
Dim nLeftOffset As Long
Dim nTopOffset As Long
Dim nLeftMargin As Long
Dim nTopMargin As Long
Dim nRightMargin As Long
Dim nBottomMargin As Long
Dim fr As FormatRange
Dim rcDrawTo As RECT
Dim rcPage As RECT
Dim nTextLength As Long
Dim nNextCharPos As Long
Dim nRet As Long
Printer.Print Space(1)
Printer.ScaleMode = vbTwips
nLeftOffset = Printer.ScaleX(GetDeviceCaps(Printer.hdc, _
PHYSICALOFFSETX), vbPixels, vbTwips)
nTopOffset = Printer.ScaleY(GetDeviceCaps(Printer.hdc, _
PHYSICALOFFSETY), vbPixels, vbTwips)
nLeftMargin = nnLeftMarginWidth - nLeftOffset
nTopMargin = nnTopMarginHeight - nTopOffset
nRightMargin = (Printer.Width - nnRightMarginWidth) _
- nLeftOffset
nBottomMargin = (Printer.Height - nnBottomMarginHeight) _
- nTopOffset
rcPage.Left = 0
rcPage.Top = 0
rcPage.Right = Printer.ScaleWidth
rcPage.Bottom = Printer.ScaleHeight
rcDrawTo.Left = nLeftMargin
rcDrawTo.Top = nTopMargin
rcDrawTo.Right = nRightMargin
rcDrawTo.Bottom = nBottomMargin
fr.hdc = Printer.hdc
fr.hdcTarget = Printer.hdc
fr.rc = rcDrawTo
fr.rcPage = rcPage
fr.chrg.cpMin = 0
fr.chrg.cpMax = -1
nTextLength = Len(rtf.Text)
Do
fr.hdc = Printer.hdc
fr.hdcTarget = Printer.hdc
nNextCharPos = SendMessage(rtf.hWnd, EM_FORMATRANGE, _
True, fr)
If nNextCharPos >= nTextLength Then Exit Do
fr.chrg.cpMin = nNextCharPos
Printer.NewPage
Printer.Print Space(1)
Loop
Printer.EndDoc
nRet = SendMessage(rtf.hWnd, EM_FORMATRANGE, _
False, ByVal CLng(0))
PrintRTF = True
Exit Function
ErrorHandler:
PrintRTF = False
End Function