Thank you for the new information.

Code: Select all
#PD_NONETWORKBUTTON = $200000
Global PrinterDC
Procedure StartPrint(Doc.s)
mDI.DOCINFO
mDI\cbSize = SizeOf(DOCINFO)
mDI\lpszDocName = @Doc
mDI\lpszOutput = 0
StartDoc_(PrinterDC,mDI)
EndProcedure
Procedure PrintRichText(hWnd, hInst, rtfEdit, LM, RM, TM, BM)
fr.FORMATRANGE
pd.PRINTDLG
pd\lStructSize = SizeOf(PRINTDLG)
pd\hwndOwner = hWnd
pd\hDevMode = 0
pd\hDevNames = 0
pd\nFromPage = 0
pd\nToPage = 0
pd\nMinPage = 0
pd\nMaxPage = 0
pd\nCopies = 0
pd\hInstance = hInst
pd\Flags = #PD_HIDEPRINTTOFILE | #PD_NONETWORKBUTTON |#PD_RETURNDC | #PD_PRINTSETUP
pd\lpfnSetupHook = 0
pd\lpSetupTemplateName = 0
pd\lpfnPrintHook = 0
pd\lpPrintTemplateName = 0
If PrintDlg_(pd)
PrinterDC = pd\hDC
Else
PrinterDC = DefaultPrinter()
EndIf
If PrinterDC
fr\hdc = PrinterDC
fr\hdcTarget = PrinterDC
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
iWidthTwips = Int((GetDeviceCaps_(PrinterDC, #HORZRES)/GetDeviceCaps_(PrinterDC, #LOGPIXELSX))*1440)
iHeightTwips = Int((GetDeviceCaps_(PrinterDC, #VERTRES )/GetDeviceCaps_(PrinterDC, #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
StartPrint("RTF Printing")
StartPage_(PrinterDC)
iTextOut = 0
iTextAmt = SendMessage_(rtfEdit, #WM_GETTEXTLENGTH, 0, 0)
While iTextOut<iTextAmt
iTextOut = SendMessage_(rtfEdit, #EM_FORMATRANGE, 1, fr)
If iTextOut < iTextAmt
;EndPage_(PrinterDC)
;StartPage_(PrinterDC)
fr\chrg\cpMin = iTextOut
fr\chrg\cpMax = -1
iTextAmt = iTextAmt - iTextOut
iTextOut = 0
EndIf
Wend
SendMessage_(rtfEdit, #EM_FORMATRANGE, 1, 0)
EndPage_(PrinterDC)
EndDoc_(PrinterDC)
DeleteDC_(PrinterDC)
EndIf
EndProcedure
Procedure StreamFileInCallback(hFile, pbBuff, cb, pcb)
ProcedureReturn ReadFile_(hFile, pbBuff, cb, pcb, 0)!1
EndProcedure
Procedure loadFile(pFilePath.s)
If ReadFile(0, pFilePath)
If GetExtensionPart(pFilePath)="rtf"
uFormat = #SF_RTF
Else
uFormat = #SF_TEXT
EndIf
edstr.EDITSTREAM
edstr\dwCookie = FileID(0)
edstr\dwError = 0
edstr\pfnCallback = @StreamFileInCallback()
SendMessage_(GadgetID(0), #EM_STREAMIN, uFormat, edstr)
CloseFile(0)
Else
MessageRequester("Error", "Error Occured While Opening File", #PB_MessageRequester_Ok)
EndIf
EndProcedure
OpenWindow(0, 200, 50, 640, 400,"RTF PRINTING", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateMenu(0, WindowID(0))
MenuTitle("&File")
MenuItem(0, "&Open")
MenuItem(1, "&Print")
MenuItem(2, "&Quit")
EditorGadget(0, 0, 0, WindowWidth(0), WindowHeight(0))
SendMessage_(GadgetID(0), #EM_LIMITTEXT, -1, 0)
a.s="{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fcharset0 Arial;}}{\colortbl ;\red255\green0\blue0;\red0\green0\blue0;}"
a.s=a.s+"{\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\f0\fs20 Hello, this is \cf1\b\fs32 RTF\cf2\b0\fs20 direct!\cf0\par}"
*MemoryBuffer = AllocateMemory(StringByteLength(a, #PB_Ascii) + 1)
PokeS(*MemoryBuffer, a.s, -1, #PB_Ascii)
SetGadgetText(0,PeekS(*MemoryBuffer))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Menu
Select EventMenu()
Case 0
FileName$ = OpenFileRequester("", "", "RTF (*.rtf|*.rtf|Text (*.txt)|*.txt;*.bat|All files (*.*)|*.*", 0)
If FileName$
loadFile(FileName$)
EndIf
Case 1
PrintRichText(WindowID(0), GetModuleHandle_(0), GadgetID(0), 0, 0, 0, 0)
Case 2
Quit = 1
EndSelect
EndSelect
Until Quit = 1
Thank you for that. When I get out of this blasted cold, I will have other questions if that's okay?RASHAD wrote:Hi Fang
Previous post updated to hide the network button
GetModuleHandle_(0) = The Handle of the file used To create the calling process which will be used as hInstance in PRINTDLG Structure (used to Select the proper printing device)
MSDN :
hInstance
Type: HINSTANCE
If the PD_ENABLEPRINTTEMPLATE or PD_ENABLESETUPTEMPLATE flag is set in the Flags member, hInstance is a handle to the application or module instance that contains the dialog box template named by the lpPrintTemplateName or lpSetupTemplateName member.
It is not needed in our case only for completeness maybe you needed later
Code: Select all
Procedure PrintRichText(hWnd, hInst, rtfEdit, LM, RM, TM, BM)
fr.FORMATRANGE
pd.PRINTDLG
pd\lStructSize = SizeOf(PRINTDLG)
pd\hwndOwner = hWnd
pd\hDevMode = 0
pd\hDevNames = 0
pd\nFromPage = 0
pd\nToPage = 0
pd\nMinPage = 0
pd\nMaxPage = 0
pd\nCopies = 0
pd\hInstance = hInst
pd\Flags = #PD_HIDEPRINTTOFILE | #PD_NONETWORKBUTTON |#PD_RETURNDC | #PD_PRINTSETUP
pd\lpfnSetupHook = 0
pd\lpSetupTemplateName = 0
pd\lpfnPrintHook = 0
pd\lpPrintTemplateName = 0
If PrintDlg_(pd)
PrinterDC = pd\hDC
Else
PrinterDC = DefaultPrinter()
EndIf
If PrinterDC
fr\hdc = PrinterDC
fr\hdcTarget = PrinterDC
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
iWidthTwips = Int((GetDeviceCaps_(PrinterDC, #HORZRES)/GetDeviceCaps_(PrinterDC, #LOGPIXELSX))*1440)
iHeightTwips = Int((GetDeviceCaps_(PrinterDC, #VERTRES )/GetDeviceCaps_(PrinterDC, #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
StartPrint("RTF Printing")
StartPage_(PrinterDC)
iTextOut = 0
iTextAmt = SendMessage_(rtfEdit, #WM_GETTEXTLENGTH, 0, 0)
While iTextOut<iTextAmt
iTextOut = SendMessage_(rtfEdit, #EM_FORMATRANGE, 1, fr)
If iTextOut<iTextAmt
EndPage_(PrinterDC)
StartPage_(PrinterDC)
fr\chrg\cpMin = iTextOut
fr\chrg\cpMax = -1
iTextAmt = iTextAmt - iTextOut
iTextOut = 0
EndIf
Wend
SendMessage_(rtfEdit, #EM_FORMATRANGE, 0, 0)
EndDoc_(PrinterDC)
DeleteDC_(PrinterDC)
EndIf
EndProcedure
Yes, I know. They are for users to fill in, in their own way and language. This is a source code project and not an application for sale so each programmer must compile their own version of it for their users with their own help filled in. I made a proper PDF help file as well, that took forever.BTW : Most of your RTF Files are empty except Main & About
Thank you, I can see that.Tested with MS PDF deriver (Windows 10 x64) and it is OK now
I never waste paper but always print to virtual pdf driver. Have to complain to the folks at foxit, their product crashes at every document open now. Will have to find another free pdf driver and reader.Testing with HP are costly so you do it and report![]()
I've been using Sumatra PDF on 3 Windows 10 machines with no problems, and very light-weight, as well.Will have to find another free pdf driver and reader.
Yes, I've tried that a few others thanks. I found a hint in the foxit forum that if you turn off the advert, foxit will no longer crash when launching or loading a document and it works.blueb wrote:I've been using Sumatra PDF on 3 Windows 10 machines with no problems, and very light-weight, as well.Will have to find another free pdf driver and reader.
http://www.sumatrapdfreader.org/free-pdf-reader.html
Never heard of that one, will try it too, thanks!RASHAD wrote:Try NCH Bolt PDF printer driver