Announcement

Collapse
No announcement yet.

Images and RichEdit control - source code of Jose Roca

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Images and RichEdit control - source code of Jose Roca

    I found source code of Jose for displaying rtf text including images in a RichTextControl.

    https://forum.powerbasic.com/forum/u...chedit-control

    Please refer article #14

    I want to show several rtf texts (with images) in the RichTextControl one after the other by mouse click. The RichTextControl should not be destroyed during this.

    What should I do to free the RichTextControl from the old content, also with regard to memory leaks?

    Regards

  • #2
    You may use any of these...

    Code:
    SendMessage(hRichEdit, %WM_SETTEXT, 0, BYVAL 0) 'Replace whole text with NUL
    
    'or
    
    SendMessage(hRichEdit, %EM_SETSEL, 0, -1) 'Select whole text
    PostMessage(hRichEdit, %WM_CLEAR, 0, 0)   'Clear text, this can be undone by an EM_UNDO message
    
    'or
    
    SendMessage(hRichEdit, %EM_SETSEL, 0, -1)              'Select whole text
    SendMessage(hRichEdit, %EM_REPLACESEL, %TRUE, BYVAL 0) 'Clear text, this can be undone by an EM_UNDO message
    Last edited by Pierre Bellisle; 18 Jan 2019, 03:18 PM.

    Comment


    • #3
      Hi Pierre, thanks for the reply. If I understand correctly now, it is not necessary to free the RT-Control from the old content before a new RTF is displayed. A simple overwriting seems to be enough. I had doubts about the for me unknown technique OLE/COM Interface. A set STDOUT indicates that the function Reo_DeleteObject is executed each time the content is overridden.

      Regards


      Comment


      • #4
        Looking at it again,
        In this context the WM_CLEAR won't do well because the subclassing of the edit.
        I saw some font residue using EM_REPLACESEL so it is not as good as I thought.
        I don't think of any memory leak but more of some garbage left in the control.

        RichEditSetString() sub was written for the demo purpose,
        in your case, if you need a little more, here is a routine
        that could be used to clear or replace the text in a clean way.

        Code:
        RichEditUpdateString(hEdit, $NUL)        'Erase
        RichEditUpdateString(hEdit, sNewRtfText) 'Update text
        
        '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
        ' Update a Rich Edit's RTF string
        '------------------------------------------------------------------------------
        SUB RichEditUpdateString(hRichEdit AS DWORD, sRtfText AS STRING)
          LOCAL eStream AS EDITSTREAM
        
          gPtr                = STRPTR(sRtfText)
          gPos                = 1 'Position in text to start from
          eStream.pfnCallback = CODEPTR(RichEditStreamInString) 'Pointer to RichEdit callback procedure
          SendMessage(hRichEdit, %EM_STREAMIN, %SF_RTF, VARPTR(eStream)) 'Stream in text
        
        END SUB
        
        '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
        '

        Comment


        • #5
          What might be a little confusing is the use of gTxt as a global.
          In fact all you have to do is update it and call RichEditSetString(hEdit).
          Code:
          LOCAL sBack AS STRING
          sBack = gTxt
          gTxt  = "{\rtf1\ansi\ansicpg1252\deff0\deflang3084{\fonttbl{\f0\fnil\fcharset0 Arial;}" & _
                  "{\f1\fnil\fcharset0 Calibri;}} {\*\generator Msftedit 5.41.21.2510;}\viewkind4\" & _
                  "uc1\pard\sl240\slmult1\lang9\fs20 RichText\f1\fs22\par}"
          RichEditSetString(hEdit)
          InvalidateRect(hEdit, BYVAL %NULL, 0) : UpdateWindow hEdit
          SLEEP 1500
          gTxt = sBack
          RichEditSetString(hEdit)

          Comment


          • #6
            Hello Pierre,
            you helped me a lot, more than you guessed - thank you.
            And anyway, it is quite great of you that you always put your expertise here in the forum.


            Comment


            • #7
              Hi Norbert,

              Coding is fun, it's good to share, to give back a little of what other gave to me.

              Comment

              Working...
              X