Richedit Control

Richedit Control

Postby ryugarai27 » Tue Dec 20, 2011 9:02 am

Hi All,

Below code snippet loads an RTF file. I want to automatically manipulate the contents, insert/delete some text on the control automatically ( within the program, much as like typing the words manually ). But I can't find any function to insert text automatically any words on a richedit control, and without losing the format. When I use :SetText() function, it replaces all the contents of the control.

What i needed is to insert text without losing the current contents, and the inserted text will have the format of the text it precedes...

Hope somebody encountered a solution for this....thanks.

--------------------testrich.prg----------------------------------
// FWH and FW++ RichEdit sample

#include "FiveWin.ch"
#include "Constant.ch"
#include "WColors.ch"
#include "RichEdit.ch"

STATIC oMsg, oLen, oRow, oCol

//----------------------------------------------------------------------------//

function Main()

local oDlg, oRich
local hRichDLL := LoadLibrary( "riched32.dll" )
local lSyntaxHL := .f.
local aF, aF2

DEFINE DIALOG oDlg NAME "Test"

oRich = TRichEdit():Redefine( 100, { || "" }, oDlg )
oRich:lHighLight = .f.

REDEFINE BUTTON ID 110 ;
ACTION oRich:SetText( MemoRead( "TestRich.prg" ) )

REDEFINE CHECKBOX lSyntaxHL ID 115 OF oDlg ;
ON CHANGE ( oRich:lHighLight := lSyntaxHL,;
oRich:SetText( oRich:GetText() ) )

REDEFINE BUTTON ID 120 ;
ACTION oRich:LoadFromRTFFile( cGetFile( "RTF file (*.rtf) | *.rtf" ) )

REDEFINE BUTTON ID 998 ACTION ( Test( oRich, oDlg ) )

ACTIVATE DIALOG oDlg CENTERED;
ON INIT ( SendMessage( oRich, EM_GETAUTOURLDETECT ) )

FreeLibrary( hRichDLL )



return nil

//----------------------------------------------------------------------------//

function Test( oRich, oDlg )

IF oRich:IsSelection()
oRich:SetText( "test" + cvaltochar(oRich:GetSel()) )
ELSE
Msginfo( 'Nothing selected! ')
END

RETURN ( nil )


----------------------testrich.rc------------------------------------------
#include "..\..\..\include\winapi.ch"

#define IDC_EDIT1 101
Test DIALOG 41, 64, 409, 229
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
CHECKBOX "Activate syntax highlight", 115, 65, 182, 92, 11, BS_AUTOCHECKBOX | WS_TABSTOP
PUSHBUTTON "L&oad RTF file", 120, 162, 179, 50, 16
PUSHBUTTON "&End", IDCANCEL, 290, 179, 50, 16
PUSHBUTTON "&Test", 998, 354, 179, 50, 16
}
User avatar
ryugarai27
 
Posts: 65
Joined: Fri Feb 13, 2009 12:03 pm
Location: Manila, Philippines

Re: Richedit Control

Postby Antonio Linares » Tue Dec 20, 2011 10:57 am

Have you tried the Method Paste() ?

it should insert the clipboard contents at the current caret position.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42085
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 116 guests