How to print data from richtext control ?
Posted: Thu Jun 12, 2003 9:23 am
I'm trying to print the contents of a richtext control. Can anyone help me with this ? Thanks.
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
Procedure PrintRichTextBox(hWnd, hInstance, TM, LM, rtfEdit)
pd.PRINTDLGAPI
pd\lStructSize = SizeOf(PRINTDLGAPI)
pd\hWndOwner = hWnd
pd\hDevMode = #NULL
pd\hDevNames = #NULL
pd\nFromPage = 0
pd\nToPage = 0
pd\nMinPage = 0
pd\nMaxPage = 0
pd\nCopies = 0
pd\hInstance = hInstance ;GetModuleHandle_(0);hInstance.l
pd\Flags = #PD_RETURNDC | #PD_NOPAGENUMS | #PD_PRINTSETUP
pd\lpfnSetupHook = #NULL
pd\lpPrintSetupTemplateName = #NULL
pd\lpfnPrintHook = #NULL
pd\lpPrintTemplateName = #NULL
If PrintDlg_( pd )
fr.FORMATRANGE
fr\hdcTarget = pd\hDC
fr\chrg\cpMin = 0
fr\chrg\cpMax = -1
fr\rc\Top = TM * 1440
fr\rcPage\Top = fr\rc\Top
fr\rc\Left = LM * 1440
fr\rcPage\Left = fr\rc\Left
;Get page dimensions in Twips
iWidthTwips = Int(( GetDeviceCaps_( pd\hDC, #HORZRES ) / GetDeviceCaps_( pd\hDC, #LOGPIXELSX )) * 1440 )
iHeightTwips = Int(( GetDeviceCaps_( pd\hDC, #VERTRES ) / GetDeviceCaps_( pd\hDC, #LOGPIXELSY )) * 1440 )
fr\rc\Right = iWidthTwips - RM * 1440
fr\rcPage\Right = fr\rc\Right
fr\rc\Bottom = iHeightTwips - BM * 1440
fr\rcPage\Bottom = fr\rc\Bottom
StartPrinting("test")
iTextOut = 0
iTextAmt = SendMessage_( rtfEdit, #WM_GETTEXTLENGTH, 0, 0 )
While iTextOut < iTextAmt
iTextOut = SendMessage_( rtfEdit, #EM_FORMATRANGE, 1, *fr )
If iTextOut = 0
iTextAmt = -1
EndIf
If iTextOut < iTextAmt ;
NewPrinterPage()
fr\chrg\cpMin = iTextOut
fr\chrg\cpMax = - 1
EndIf
Wend
SendMessage_( rtfEdit, #EM_FORMATRANGE, 1, #NULL)
; Finish the printing.
StopPrinting()
Else
MessageRequester("Info","Canceled !",0)
EndIf
EndProcedure
#WindowWidth = 640
#WindowHeight = 480
hWnd = OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget, "PureBasic - Gadget Demonstration")
If CreateGadgetList(WindowID())
EditorGadget(7, 10, 5, 700, 55)
SetGadgetText(7,"PureBasic demonstation")
hInstance = GetModuleHandle_(0)
If DefaultPrinter() <> 0
PrintRichTextBox(hWnd, hInstance, 1, 1, GadgetID(7))
EndIf
EndIf