Code: Select all
EnableExplicit
Global TheRTF.s = "{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang2057{\fonttbl{\f0\fnil\fcharset0 Calibri;}}{\colortbl ;\red0\green77\blue187;}{\*\generator Riched20 10.0.22621}\viewkind4\uc1 \pard\sa200\sl276\slmult1\ul\f0\fs22\lang9 This is some underline text\ulnone .\par\b This is some bold text\par\b0\i This is some italic text\par\cf1\ul\b This is some bold italic underline blue text.\cf0\ulnone\b0\par}"
Global EventId.i, HLibrary.i, RichEditControlHandle.i
Global RTFRemainingBytes.i, RTFCurrentPoint.i, HLibrary.i
Procedure.i EditStreamCallback(lCookie.i, pbBuffer.i, CB.i, pcbTransfered.i)
;lCookie contains starting address of Data
Protected BytesToTransferThisTime.i
If RTFRemainingBytes = 0
RtlMoveMemory_(pcbTransfered, @RTFRemainingBytes, 4) ; stops calling back
ProcedureReturn
EndIf
If CB <= RTFRemainingBytes
BytesToTransferThisTime = CB
Else
BytesToTransferThisTime = RTFRemainingBytes
EndIf
RtlMoveMemory_(pbBuffer, lCookie + RTFCurrentPoint, BytesToTransferThisTime)
RtlMoveMemory_(pcbTransfered, @BytesToTransferThisTime, 4)
RTFRemainingBytes = RTFRemainingBytes - BytesToTransferThisTime
RTFCurrentPoint = RTFCurrentPoint + BytesToTransferThisTime
EndProcedure
Procedure StreamTextIn(TheEditBoxH.i, TheRTF.s)
Protected EStream.EditStream
Protected ReturnValue.i
Protected Dim AsciiRtfArray.b(Len(TheRTF))
PokeS(@AsciiRtfArray(), TheRTF, -1, #PB_Ascii)
EStream\dwCookie = @AsciiRtfArray()
EStream\pfnCallback = @EditStreamCallback()
RTFRemainingBytes = Len(TheRTF): RTFCurrentPoint = 0
ReturnValue = SendMessage_(TheEditBoxH, #EM_STREAMIN, #SF_RTF, @EStream)
EndProcedure
Procedure.i CreatEditControl(hParent.i)
Protected eXTEditBoxClassName.s = "RichEdit50W"
Protected lStyle.i, ReturnValue.i, theBox.i
lStyle = #WS_CHILD | #WS_CLIPSIBLINGS | #ES_MULTILINE | #WS_VSCROLL | #WS_VISIBLE
theBox = CreateWindowEx_(0, @eXTEditBoxClassName, #Null, lStyle, 24, 24, 350, WindowHeight(0) - 70, hParent, 0, GetModuleHandle_(0), 0)
ProcedureReturn thebox
EndProcedure
HLibrary = LoadLibrary_("Msftedit.dll")
If OpenWindow(0, 0, 0, 800, 200, "Rich Text example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
RichEditControlHandle = CreatEditControl(WindowID(0))
TextGadget(1, 14, 5, 350, 20, "Rich Edit Control Created with CreateWindowEx", #PB_Text_Center)
TextGadget(2, 400, 4, 350, 20, "Rich Edit Gadget Created with Pure Basic", #PB_Text_Center)
EditorGadget(3, 400, 24, 350, WindowHeight(0) - 70, #PB_Editor_ReadOnly | #PB_Editor_WordWrap)
StreamTextIn(GadgetID(3), TheRTF)
StreamTextIn(RichEditControlHandle, TheRTF)
Repeat
EventId = WaitWindowEvent()
Select EventId
EndSelect
Until EventId = #PB_Event_CloseWindow
EndIf
FreeLibrary_(HLibrary)
(Interesting note: the above code runs in PB 5.46, which uses an earlier version of the Rich Edit Control, and both controls are filled with text.)


