Need some help using RichEdit_GetCharFormat in WinFBE

Windows specific questions.
Post Reply
AngFerreiras
Posts: 6
Joined: Dec 10, 2022 5:10

Need some help using RichEdit_GetCharFormat in WinFBE

Post by AngFerreiras »

I'm trying to program a simple text editor using WinFBE and having an issue to make the call RichEdit_GetCharFormat to transfer the selected text format to a variable.

I have tried lines like:

Code: Select all

 SendMessage(editor.RichEdit1.hWindow, EM_GETCHARFORMAT, SCF_SELECTION, cast(lparam, @Rformato))
 RichEdit_GetCharFormat( editor.RichEdit1.hWindow, SCF_SELECTION, @Rformato )
Getting no errors or warnings so I'm not sure from were the problem comes, it doesn't matter if i use CHARFORMAT or CHARFORMATW structures, it does not work.
I had checked in win32 threads related to the EM_GETCHARFORMAT message and this seems to be the right method.

Here is the code i`m using for the function: (most of it is to see where the problem is)

Code: Select all

Function Editor_BEstado_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
	Rem >>Declarations for the format structure<< 
	Dim As Longint Resultado
	dim as string StrdwMask
	Dim as string StrdwEffects
	dim as string MsgResultado
	dim as CHARFORMATW Rformato 
	
	Rem >>Verifying test to make sure the text was actually selected<< 
	If RichEdit_GetSelText(editor.RichEdit1.hWindow) = 0 then Afxmsg("No hay texto seleccionado", "Texto seleccionado")
	if RichEdit_GetSelText(editor.RichEdit1.hWindow) > 0 then Afxmsg("Texto seleccionado: " + RichEdit_GetSelText(editor.RichEdit1.hWindow), "Texto seleccionado")

	
	Rem >>Clear and define values for Rformato<<
	Rformato.cbSize = SizeOf(Rformato)
	' ZeroMemory(@Rformato, SizeOf(Rformato)) 
	RtlZeroMemory(@Rformato, SizeOf(Rformato))
	
	Rem >>Get the format of the selected text<< 
	' (Here is where seems to be a problem, since EM_GETCHARFORMAT or RichEdit_GetCharFormat calls both fail to transfer the format to Rformato, using CHARFORMATW, CHARFORMAT, or CHARFORMATW2 structures) 
	Resultado = RichEdit_GetCharFormat(editor.RichEdit1.hWindow, SCF_SELECTION, @Rformato)
	 ' Resultado = SendMessage(editor.RichEdit1.hWindow, EM_GETCHARFORMAT, SCF_SELECTION, cast(lparam, VarPtr(Rformato)))

	 
	Rem >>Define the monitoring message<< (Test that indicates if the RichEdit_GetCharFormat call was successful) 
	If Resultado = 0 Then MsgResultado = "1- RichEdit_GetCharFormat No se ejecuto correctamente"
	If Resultado = 1 Then MsgResultado = "1- RichEdit_GetCharFormat se ejecuto correctamente"
	If Rformato.dwEffects = CFM_BOLD Then 
		StrdwMask  = "2- Rformato.dwMask = CFM_BOLD"
		StrdwEffects = "3- Rformato.dwEffects = CFM_BOLD" 
		MessageBox(0, MsgResultado + !"\n" + StrdwMask + !"\n" + StrdwEffects + !"\n" + "4- Texto en negritas", "Estado", MB_OK)
	elseif Rformato.dwEffects = null then
		StrdwMask  = "2- Rformato.dwMask = Null"	
		StrdwEffects = "3- Rformato.dwEffects = Null" 
		MessageBox(0, MsgResultado + !"\n" + StrdwMask + !"\n" + StrdwEffects + !"\n" + "4- Texto normal", "Estado", MB_OK)
	end if

	Function = 0
End Function


Any ideas about what's happening?
adeyblue
Posts: 299
Joined: Nov 07, 2019 20:08

Re: Need some help using RichEdit_GetCharFormat in WinFBE

Post by adeyblue »

AngFerreiras wrote: Mar 28, 2023 18:22

Code: Select all

	Rem >>Clear and define values for Rformato<<
	Rformato.cbSize = SizeOf(Rformato)
	' ZeroMemory(@Rformato, SizeOf(Rformato)) 
	RtlZeroMemory(@Rformato, SizeOf(Rformato))
Looks like you've got those two lines the wrong way around. Need to zero it first, then set the cbSize. Though you don't need to zero it at all, it happens automatically when you dim it in FreeBasic
AngFerreiras
Posts: 6
Joined: Dec 10, 2022 5:10

Re: Need some help using RichEdit_GetCharFormat in WinFBE

Post by AngFerreiras »

adeyblue wrote: Mar 30, 2023 23:15 Looks like you've got those two lines the wrong way around. Need to zero it first, then set the cbSize. Though you don't need to zero it at all, it happens automatically when you dim it in FreeBasic
Thanks, that did the work
Post Reply