IonicWind Software

Creative Basic => General Questions => Topic started by: aurelCB on May 20, 2008, 03:38:08 am

Title: How highlite line in RichEdit control
Post by: aurelCB on May 20, 2008, 03:38:08 am
Hi all...
I have question.
If i'm load in richedit control for example 3 lines of text.
How can i highlite for example second line?
I try this but dont work:
Code Select
DEF w1:WINDOW
DEF nchar:INT
DEF second:INT
DEf linecount,linenum:INT
def text$:string
WINDOW w1,0,0,500,300,@MINBOX|@MAXBOX|@SIZE,0,"Simple Window",main
setwindowcolor w1,rgb(180,180,180)
CONTROL w1,"RE,,10,10,400,200,@cteditmulti|@hscroll|@vscroll,1"
SETFONT w1,"Courier New",10, 400,0,1

CONTROL w1,"B,Paste,31,240,70,20,0x50000000,2"
SETFONT w1,"&H1",8, 400,0,2
CONTROL w1,"B,Highlite Line,124,240,70,20,0x50000000,3"
SETFONT w1,"&H1",8, 400,0,3

run=1
WAITUNTIL run = 0
CLOSEWINDOW w1
END
'copy & paste next 3 lines pressing button Paste
'0123456789
'ABCDEFGHIJ
'YXCVBNMKLO

SUB main
    select @CLASS
case @idclosewindow
        run=0

case @idcontrol
'button paste
IF @controlid=2
CONTROLCMD w1,1,@RTPASTE
ENDIF
'button highlite
IF @controlid=3
linecount = CONTROLCMD (w1,1, @RTGETLINECOUNT)
linecount=linecount-1
'show linecount(linecount=3)
messagebox w1,"Lcount: " + str$(linecount),"Count"
'set linenum to 2
linenum=2
text$ = CONTROLCMD ( w1, 1, @RTGETLINE, linenum)
messagebox w1,"selected line: " + text$,"text"
CONTROLCMD w1,1, @RTHIDESEL, 0           
nchar=LEN((CONTROLCMD (w1,1, @RTGETLINE,linenum)))
' second=LEN((CONTROLCMD (w1,1, @RTGETLINE,linenum)))
messagebox w1,"len: " + str$(nchar),"len"
CONTROLCMD w1,1, @RTSETSELECTION, 0,nchar   
ENDIF

   endselect
RETURN
Title: Re: How highlite line in RichEdit control
Post by: LarryMc on May 20, 2008, 12:48:38 pm
Code Select
DEF w1:WINDOW
DEF nchar,second,linecount,linenum,char_start, char_end,linelength:INT
def text$:string

WINDOW w1,0,0,600,300,@MINBOX|@MAXBOX|@SIZE,0,"Simple Window",main
setwindowcolor w1,rgb(180,180,180)
CONTROL w1,"RE,,10,10,500,200,@cteditmulti|@hscroll|@vscroll,1"
SETFONT w1,"Courier New",10, 400,0,1

CONTROL w1,"B,Paste,31,240,70,20,0x50000000,2"
SETFONT w1,"&H1",8, 400,0,2
CONTROL w1,"B,Highlite Line,124,240,70,20,0x50000000,3"
SETFONT w1,"&H1",8, 400,0,3

run=1
WAITUNTIL run = 0
CLOSEWINDOW w1
END
'copy & paste next 3 lines pressing button Paste
'0123456789
'ABCDEFGHIJ
'YXCVBNMKLO

SUB main
select @CLASS
case @idclosewindow
        run=0
case @idcontrol
select @controlid
case 2 :'button paste
CONTROLCMD w1,1,@RTPASTE
case 3 :'button highlite
linecount = CONTROLCMD (w1,1, @RTGETLINECOUNT)
'set linenum to 2 which is actually line 3
linenum=2
text$ = CONTROLCMD ( w1, 1, @RTGETLINE, linenum)
linelength=len(text$)
char_start = SendMessage( w1, 0xbb, linenum,0,  1)
char_end = char_start + linelength 
CONTROLCMD w1, 1, @RTSETSELECTION, char_start, char_end
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(255, 0, 0)
endselect
   endselect
RETURN
Title: Re: How highlite line in RichEdit control
Post by: aurelCB on May 22, 2008, 02:54:04 am
Thanks mr.Larry!
You give me idea how highlite work.
I do some changes in your code and finaly work properly.
And finaly i understand what sendmessage doing.
char_start is lparam from sendmessage and is 0,wparam is linenum
only i dont know what is 0xbb but work.
Code Select
DEF w1:WINDOW
'Added by Larry McCoughn
DEF linenum,char_start,char_end,linelength:INT
def text$:string
WINDOW w1,0,0,430,300,@MINBOX|@MAXBOX|@SIZE,0,"Highlite Line in RichEdit",main
Setwindowcolor w1,rgb(200,200,200)
'CONTROL w1,"RE,,10,10,400,200,@cteditmulti|@hscroll|@vscroll,1"
SETFONT w1,"Courier New",10, 400,0,1

CONTROL w1,"B,Paste,31,240,70,20,0x50000000,2"
SETFONT w1,"&H1",8, 400,0,2
CONTROL w1,"B,Highlite Line,124,240,70,20,0x50000000,3"
SETFONT w1,"&H1",8, 400,0,3

'Added by peterpuk ---------------------------------------------------------------
setcontroltext w1,1,"This is a sample to show" + chr$(13)
setcontroltext w1,1,getcontroltext(w1,1) + "how to select and highlight(error)" + chr$(13)
setcontroltext w1,1,getcontroltext(w1,1) + "the line of text."
'----------------------------------------------------------------------------------
run=1
WAITUNTIL run = 0
CLOSEWINDOW w1
END

SUB main
    select @CLASS
case @idclosewindow
     run=0

case @idcreate
centerwindow w1
CONTROL w1,"RE,,10,10,400,200,@cteditmulti|@cteditautoh|@hscroll|@vscroll|@border,1"

case @idcontrol
'button paste
IF @controlid=2
CONTROLCMD w1,1,@RTPASTE
ENDIF
'button highlite
IF @controlid=3
'Get the number of lines in the text control
'linecount = CONTROLCMD (w1,1, @RTGETLINECOUNT)
linenum = 1:'zero based ,if you have 3 lines (0 1 2)
text$ = CONTROLCMD ( w1, 1, @RTGETLINE,linenum)
linelength=LEN(text$)
char_start = SendMessage(w1,0xBB,linenum, 0, 1)
char_end=char_start + linelength
CONTROLCMD w1,1, @RTHIDESEL, 0           
CONTROLCMD w1,1, @RTSETSELECTION, char_start, char_end
ENDIF
   endselect
RETURN
Title: Re: How highlite line in RichEdit control
Post by: peterpuk on May 22, 2008, 09:29:11 am
The 0xBB is the message number.

Each message is represented by a number, and the message EM_LINEINDEX is the number 0xBB.

The messages are usually defined as a constant so that you know what the number means. In the start of your program you might put

CONST EM_LINEINDEX=0xBB

and then in the sendmessage you code it as

char_start = SendMessage(w1,EM_LINEINDEX,linenum, 0, 1)
Title: Re: How highlite line in RichEdit control
Post by: aurelCB on May 22, 2008, 12:50:54 pm
Super peter i just dont know.
Thanks for explain...