I am trying to make a simple terminal program for serial communications, With the clientarea divided in two parts horizontally. The upper part is the monitoring control, and the lower part the input control.
All incoming messages will be directly printed in the monitoring (upper) control, and when ENTER is pressed in the lower control, all the input text is appended to the monitoring control, and then the input control is cleared. That was the easy part...
But I am not able to get the upper control to scroll when the contents exceeds the bottom of the control. I know how to do it in IWB, but just now I should like to do it in Creative Basic. Can anyone help, please?
Regards
Egil
Below is the code I have used when trying this out. It is the sub RE_Append, way down at the bottom, I have problems with.
' test.cba
'
AUTODEFINE "OFF"
DECLARE RE_Append(win:WINDOW,id:int,text:string)
DEF win:WINDOW
DEF Rx$,Tx$:string
DEF cleft,ctop,cwidth,cheight,run:int
WINDOW win,0,0,640,280,0,0," TEST ",main
CENTERWINDOW win
SETWINDOWCOLOR win, RGB(222,222,222)
starttimer win,200,1
GETCLIENTSIZE win,cleft,ctop,cwidth,cheight
CONTROL win,"RE,,cleft,ctop+(cheight-80),cwidth,cheight,@CTEDITMULTI|@CTEDITRETURN,1"
SETCONTROLCOLOR win, 1, RGB(0,0,0), RGB(255,255,255)
SETFOCUS win, 1
CONTROL win,"RE,,cleft,ctop,cwidth,(cheight-85),@CTEDITMULTI|@VSCROLL,2"
SETCONTROLCOLOR win, 1, RGB(0,0,0), RGB(255,255,255)
run = 1
WAITUNTIL run = 0
stoptimer win,1
CLOSEWINDOW win
END
SUB main
SELECT @CLASS
case @IDCLOSEWINDOW
run=0
case @idtimer
if GETKEYSTATE(13) <> 0 :' ENTER is pressed
Tx$ = GETCONTROLTEXT (win, 1) :' Retrieve text from input control
RE_Append(win,2,Tx$) :' Append the text to the monitor control
SETCONTROLTEXT win, 1, "" :' Clear input control
endif
if GETKEYSTATE(27) <> 0 :' ESC is pressed - program terminates
run=0
endif
ENDSELECT
RETURN
'=======================================================================
Sub RE_Append(win:WINDOW,id:int,text:string)
def re$[65535]:istring
re$ = GETCONTROLTEXT (win, 2)
re$ = re$ + text
SETCONTROLTEXT win, 2, re$
RETURN
'=======================================================================
I think this will do what you want Egil.
Sub RE_Append(win:WINDOW,id:int,text:string)
def re$[65535]:istring
def count:int
def lines:int
re$ = GETCONTROLTEXT (win, 2)
re$ = re$ + text
SETCONTROLTEXT win, 2, re$
count = CONTROLCMD ( win, 2, @RTGETLINECOUNT)
lines = CONTROLCMD ( win, 2, @RTGETFIRSTLINE)
CONTROLCMD win, 2, @RTSCROLL, count-lines-11, 0
RETURN
LarryMc
Good point Larry.. ;)
Work fine.
Thanks Larry!
Working fine now. :D
Regards
Egil
I changed Larry's code slightly to take care of different program window heights.
Changed the line:
CONTROLCMD win, 2, @RTSCROLL, count-lines-11, 0
to
CONTROLCMD win, 2, @RTSCROLL, count-lines-((cheight-85)/17), 0
This works fine with my default font.
Later I will try to find a method that will cope with different font-heights automaticly. But first I'll finish the communication routines.
Regards
Egil