FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Richedit text from a string
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Richedit text from a string
Posted: Sun Jan 08, 2012 02:24 PM
Hi all,

I am trying to display a rtf string in a richedit control without success. What is wrong with the following code

Code (fw): Select all Collapse
cText := "{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Courier New;}}"+CRLF+;
"{\colortbl ;\red0\green77\blue187;\red192\green80\blue77;}"+CRLF+;
"{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\cf1\lang1031\f0\fs22 This is \b colored \b0 text\cf0 . \cf2 The background is color 1 and the foreground is color 2\cf0\par"+CRLF+;
"}"
oRtf := TRichEdit():Redefine( 4000, { || "" }, oDlg )
//oRtf:lHighLight = .f.
oRtf:LoadRTF (cText)  // does not work
oRTF:Refresh()
//oRtf:LoadFromRTFFile( "Register.rtf" )  / from a file it is working


IsRTF (cText) returns .t., but it´s only working if I load it from a file.

Any help appreciated
kind regards

Stefan
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Richedit text from a string
Posted: Mon Jan 09, 2012 05:22 AM
The following code is working fine here.

Instead of
oRtf:LoadRTF (cText)
Try
oRtf:SetText( cText )


Test.Prg
Code (fw): Select all Collapse
#Include "FiveWin.ch"
//----------------------------------------------------------------------------//
Function Main()

   Local oDlg, oRich, cRtf
   Local hRichDLL := LoadLibrary( "riched20.dll" )
   
   cRtf:="{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Courier New;}}"+CRLF+;
            "{\colortbl ;\red0\green77\blue187;\red192\green80\blue77;}"+CRLF+;
            "{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\cf1\lang1031\f0\fs22 This is \b colored \b0 text\cf0 . \cf2 The background is color 1 and the foreground is color 2\cf0\par"+CRLF+;
            "}"   

   DEFINE DIALOG oDlg NAME "Test"

   oRich = TRichEdit():Redefine( 100, { || "" }, oDlg )
   oRich:SetText( cRtf )
   oDlg:bStart = { || oRich:SetPos( 0 )}

   ACTIVATE DIALOG oDlg CENTERED 

   FreeLibrary( hRichDLL )

Return nil


Test.RC
Code (fw): Select all Collapse
#define IDC_EDIT1   101
Test DIALOG 41, 64, 409, 199
STYLE DS_MODALFRAME | 0x4L | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Testing the RichEdit control"
FONT 8, "MS Sans Serif"
{
 CONTROL "", 100, "RichEdit20A", 4100 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 6, 12, 398, 163
 PUSHBUTTON "&Load text file", 110, 5, 179, 50, 16
}




Regards
Anser
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Re: Richedit text from a string
Posted: Mon Jan 09, 2012 02:47 PM

Anser,

thanks, you put me in the right direction.

I tried :SetText(), the text was shown with all the control characters. The difference was in the .rc file. PellesC inserted a controltype "RichEdit20W", which is not working. If I change this to "RichEdit20A", everything works fine.

kind regards

Stefan
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: Richedit text from a string
Posted: Thu Jan 12, 2012 08:38 PM

Stefan;

Check this thread:

viewtopic.php?f=3t=15270

I had shown a short-fast-very simple function to extract text from an rtf field using regular expressions. The nice thing about it is that you don't need to create the rtf object in order to execute GetText() method.

Reinaldo.

&

Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Re: Richedit text from a string
Posted: Fri Jan 13, 2012 12:25 PM

Reinaldo,

thanks, I know this thread and your function is very usefull.

But in my case I wanted to display a formatted string and so I needed the rtf-class. And I found this class does work with other controltypes than "RichEdit20A".

kind regards

Stefan
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Re: Richedit text from a string
Posted: Fri Jan 13, 2012 02:20 PM

RichEdit20A is for Ansitext, RichEdit20W for Unicode. It seems that ::SetText() does not work with unicode, ::Loadrtf () does.

kind regards

Stefan

Continue the discussion