Unable to Stream Rich Text to Editor Gadget

Just starting out? Need help? Post your questions and find answers here.
CalamityJames
User
User
Posts: 81
Joined: Sat Mar 13, 2010 4:50 pm

Unable to Stream Rich Text to Editor Gadget

Post by CalamityJames »

I am unable to stream rich text format text into the Editor Gadget in PB 6.04 (or 6.10 for that matter). The coding to stream the text is clearly correct because I can stream text into a Rich Edit Control created by the windows function CreateWindowEx. The following code illustrates the point:

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)
Am I missing something?
(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.)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4993
Joined: Sun Apr 12, 2009 6:27 am

Re: Unable to Stream Rich Text to Editor Gadget

Post by RASHAD »

Hi

Code: Select all

SendMessage_(GadgetID(3), #EM_SETTEXTMODE, #TM_RICHTEXT, 0)
Egypt my love
CalamityJames
User
User
Posts: 81
Joined: Sat Mar 13, 2010 4:50 pm

Re: Unable to Stream Rich Text to Editor Gadget

Post by CalamityJames »

Thanks to Rashad. I had a feeling that it was one of those things which are simple - when you know how!
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Unable to Stream Rich Text to Editor Gadget

Post by jacdelad »

https://www.purebasic.fr/english/viewto ... DE#p612651
https://www.purebasic.fr/english/viewto ... DE#p605710
https://www.purebasic.fr/english/viewto ... DE#p599737
...and some more. But it's a relatively new change and really hard to find if you don't know where to start. A lot of people stumbled over it.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply