RichEdit question

Started by Frank Bruebach, July 07, 2026, 01:15:57 PM

Previous topic - Next topic

Frank Bruebach


hello. How I can send text to an rich edit control?
I have got an error Type mismatch at parameter 1.. SendMessageW()
I wanted to update my code example from afx to afxnova ;)

thanks, frank


#define UNICODE
'#define _CREC_DEBUG_ 1
#include once "AfxNova/CWindow.inc"
#include once "AfxNova/CRichEditCtx.inc"
' #include once "AfxNova/CRichEditOleCallback.inc"
USING AfxNova
...

' // Add a rich edit control2
   DIM pRichEdit2 AS CRichEditCtx = CRichEditCtx(@pWindow, IDC_RICHEDIT2, "edit2", 10, 10, _
      pWindow.ClientWidth - 460, pWindow.ClientHeight - 160, -1, 0)
''WS_VISIBLE OR WS_TABSTOP OR ES_LEFT OR WS_VSCROLL OR ES_MULTILINE OR ES_WANTRETURN OR ES_NOHIDESEL OR ES_SAVESEL)
 
   ' // Fill the control with some data
   DIM dwsText AS DWSTRING
   dwsText="Hello2 Editor"
   
   SendMessageW ( pRichEdit2, WM_SETTEXT, IDC_RICHEDIT2 , strptr(dwsText) )
 
   ' // Change the default font
   'pRichEdit.SetFont("Times New Roman", 12)
   SetFocus pRichEdit.hRichEdit

José Roca

#1
If you inisist in using SendMessageW, you need to use

SendMessageW(pRichEdit2.hRichEdit, WM_SETTEXT, 0, CAST(LPARAM, STRPTR(dwsText)))

But you can use

pRichEdit2.SetText(dwsText)

or

pRichEdit2.Text = dwsText


Paul Squires

Makes sense to use José's suggestion of pRichEdit2.Text since you are already using the RichEdit class.

In addition to SendMessage you could also use its corresponding Afx wrapper:  AfxSetWindowText( hCtl, dwsText )
Paul Squires
PlanetSquires Software

José Roca

#3
There is extensive documentation here:

https://github.com/JoseRoca/AfxNova/tree/main/docs/Windows/WIndows%20Controls/RichEdit%20


If you want to use the Rich Edit control directly, instead of the CRichEditCtx Class, there are wrappers for all the Rich Edit messages:

https://github.com/JoseRoca/AfxNova/blob/main/docs/Windows/WIndows%20Controls/RichEdit%20/RichEdit%20Procedures.md