This is a chat like application.
The top control, a RICHEDIT, is the chat "history" and the bottom one, a TMultiGet, is the operator typing control.
If the other party types something before the operator finishes what he is typing, what the other party typed must be presented to the operator, without interfering the typing job.
If the RICHEDIT text grows beyond the RICHEDIT size, it must scrolls, in order to the last typed answer can be seen.
Basically, I need to update the RICHEDIT control position while typing some text.
The only way I found to update the RICHEDIT control is to put focus on it, but, since the operator is typing, the focus needs to go back to the TMultiGet control.
But when the TMultiGet looses focus and gets it again, the typed text becomes marked, and, when the operator keeps typing, it is deleted...
How do I update the RICHEDIT control position without putting focus on it ?
In the sample, if you keep typing while changing focus the text is deleted.
Regards,
Maurício Faria
- Code: Select all Expand view RUN
#include "fivewin.ch"
#include "richedit.ch"
function Main()
local oWnd
DEFINE WINDOW oWnd FROM 1,1 TO 140,110 PIXEL
@ 014,004 BUTTON "With SetFocus " SIZE 110,30 PIXEL ACTION Go( .T. )
@ 054,004 BUTTON "Without SetFocus " SIZE 110,30 PIXEL ACTION Go( .F. )
ACTIVATE WINDOW oWnd
return nil
Function Go( lSetFocus )
local oDlg
local cRichText
local oRich
local oTextType
local cText
local oTimer
local hRichDLL := LoadLibrary( "riched20.dll" )
DEFINE Dialog oDlg FROM 1,1 TO 400,400 PIXEL
@ 004,004 RichEdit oRich VAR cRichText OF oDlg SIZE 176,66 PIXEL READONLY
@ 108,004 GET oTextType VAR cText OF oDlg SIZE 174,78 PIXEL MULTILINE
oTimer := TTimer():New( 1000, { || UpdateRTF( oRich, oTimer, oTextType, lSetFocus ) } )
ACTIVATE Dialog oDlg ON INIT ( oTimer:Activate(), oTextType:SetFocus() )
freeLibrary( hRichDLL )
return nil
PROCEDURE UpdateRTF( oRich, oTimer, oTextType, lSetFocus )
LOCAL cHeader := "{\rtf1\ansi\ansicpg1252\deff0\deflang1046" +;
"{\fonttbl{\f0\fnil\fcharset0 Courier New;}}" +;
"{\colortbl ;\red0\green0\blue0;\red185\green255\blue86;\red255\green255\blue255;\red255\green255\blue100;}" +;
"\viewkind4\uc1\pard\b\fs18"
LOCAL cRTF := ""
LOCAL I
STATIC aMsgs
oTimer:DEACTIVATE()
IF EMPTY( aMsgs )
aMsgs := {"MSGS"}
ENDIF
AADD( aMsgs, Time() )
FOR I:=1 TO LEN( aMsgs )
IF MOD( I, 2 ) = 0
cRTF += "\cf1\highlight2 " + aMsgs[I] + "\par "
ELSE
cRTF += "\cf1\highlight3 " + aMsgs[I] + "\par "
ENDIF
NEXT
cRTF += "}"
oRich:SetText( cHeader + cRTF )
oRich:GoTo(oRich:Len())
IF lSetFocus
oRich:SetFocus()
oTextType:SetFocus()
ENDIF
oTimer:ACTIVATE()
RETURN