IonicWind Software

Creative Basic => General Questions => Topic started by: aurelCB on August 19, 2008, 02:16:51 PM

Title: Colorize text in real-time
Post by: aurelCB on August 19, 2008, 02:16:51 PM
Hi all...
I find this code made by Jos de Jong (Joske) and work ok on EBasic.
My question is :Is this posible convert this code to Creative.
Or maby do something similiar directly in Creative Basic.
Any idea ...?
Joske code:
/*
color code in rich edit control
ibasic pro code
jos de jong, 2007
*/

'Declarations
$INCLUDE "windows.inc"
CONST EM_FINDTEXT = (WM_USER + 56)
TYPE CHARRANGE
INT cpMin
INT cpMax
ENDTYPE
TYPE FINDTEXT
    CHARRANGE chrg
    POINTER lpstrText
ENDTYPE

'create a list with keywords
CONST kewordCount = 9
DEF keyword[kewordCount]:STRING
keyword[0] = "IF"
keyword[1] = "THEN"
keyword[2] = "ELSE"
keyword[3] = "ENDIF"
keyword[4] = "WHILE"
keyword[5] = "ENDWHILE"
keyword[6] = "DO"
keyword[7] = "FOR"
keyword[8] = "NEXT"


DEF d1:Dialog
CREATEDIALOG d1,0,0,587,360,0x80C80080,0,"Color code demo",&Handler
CONTROL d1,@RICHEDIT,"",7,35,570,294,0x50B010C4,1
DOMODAL d1
END


'______________________________________________________________________________
SUB Handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1

'let the rich edit control send a message when the contents have changed
mask = CONTROLCMD(d1,1,@RTGETEVENTMASK)
CONTROLCMD d1, 1, @RTSETEVENTMASK, mask | @ENMKEYEVENTS |@ENMCHANGE

SETCONTROLTEXT d1, 1, "This program can highlight keywords\nlike then and if and while...\n\nAlso the words For, next, etc."

applyColorSheet(d1, 1)

CASE @IDCONTROL
SELECT @CONTROLID
CASE 1:'richedit
SELECT @NOTIFYCODE
CASE @ENCHANGE
'the contents of the richedit are changed
applyColorLine(d1, 1)
ENDSELECT
ENDSELECT

ENDSELECT
RETURN
ENDSUB



'______________________________________________________________________________
/*
This function adjusts the colors of all lines in the sheet
*/
SUB applyColorSheet(dlg:DIALOG, ctl:INT)
INT char_start, char_end
INT linenum, linecount

'hide the selection and get the current caret position
CONTROLCMD dlg, ctl, @RTHIDESEL, 1
CONTROLCMD dlg, ctl, @RTGETSELECTION, char_start, char_end

linecount = CONTROLCMD(dlg, ctl, @RTGETLINECOUNT)
FOR linenum = 0 TO linecount-1
colorize(dlg, ctl, linenum)
NEXT linenum

'restore the original caret position and show the selection again
CONTROLCMD dlg, ctl, @RTSETSELECTION, char_start, char_end
CONTROLCMD dlg, ctl, @RTHIDESEL, 0

RETURN
ENDSUB


'______________________________________________________________________________
/*
This function adjusts the colors of the current line
*/
SUB applyColorLine(dlg:DIALOG, ctl:INT)
INT char_start, char_end
INT linenum

'hide the selection and get the current caret position
CONTROLCMD dlg, ctl, @RTHIDESEL, 1
CONTROLCMD dlg, ctl, @RTGETSELECTION, char_start, char_end

linenum = CONTROLCMD (dlg, ctl, @RTLINEFROMCHAR, char_start)
colorize(dlg, ctl, linenum)

'restore the original caret position and show the selection again
CONTROLCMD dlg, ctl, @RTSETSELECTION, char_start, char_end
CONTROLCMD dlg, ctl, @RTHIDESEL, 0

RETURN
ENDSUB

'______________________________________________________________________________
/*
This function adjusts the colors of the keywords on the given linenum
*/
SUB colorize(dlg:DIALOG, ctl:INT, linenum:INT)
INT lineStart, lineLength
INT i
INT p, pLine

lineStart = CONTROLCMD (dlg, ctl, @RTCHARFROMLINE, linenum)
lineLength = CONTROLCMD (dlg, ctl, @RTGETLINELENGTH, linenum)

'uncolor the whole line, set black color
CONTROLCMD dlg, ctl, @RTSETSELECTION, lineStart, lineStart + lineLength
CONTROLCMD dlg, ctl, @RTSETSELCOLOR, RGB(0, 0, 0)

'check the keywords one by one, if they occur on this line
FOR i=0 TO kewordCount-1
p = lineStart-1
DO
p = RTFINDTEXT(dlg, ctl, keyword[i], p+1, lineStart + lineLength, True, True)
IF p >= 0
'the keyword is found at the current line. color it
CONTROLCMD dlg, ctl, @RTSETSELECTION, p, p+LEN(keyword[i])
CONTROLCMD dlg, ctl, @RTSETSELCOLOR, RGB(255, 0, 0)

''you can also add making the text uppercase and things like that...
'CONTROLCMD dlg, ctl, @RTREPLACESEL, UCASE$(keyword[i])
ENDIF
UNTIL p < 0
NEXT i

RETURN
ENDSUB


'________________________________________________________________________
SUB RTFINDTEXT(w:DIALOG, ctl:INT, Searchtext:STRING, start_pos:INT, end_pos:INT, ignore_case:INT, match_word:INT), INT
'Searches for the given searchtext, in characters from start_pos to end_pos.
'You can choose to select ignore_case and match_word. ignore_case=1-match_case
'Returns the position of the first found match. If there is no match, then returns -1
INT pos
INT flags

FINDTEXT MyFindtext
MyFindtext.chrg.cpMin = start_pos
MyFindtext.chrg.cpMax = end_pos
MyFindtext.lpstrText = Searchtext
flags = FR_MATCHCASE*(1-ignore_case) | FR_WHOLEWORD*match_word
pos = SENDMESSAGE(w, EM_FINDTEXT, flags, MyFindtext, ctl)

    RETURN pos
ENDSUB
Title: Re: Colorize text in real-time
Post by: aurelCB on August 20, 2008, 11:10:23 PM
So what is? no one of you dont know how convert this to Creative Code.
I allways mean that i'm only here wich knowlege is small...
Title: Re: Colorize text in real-time
Post by: LarryMc on August 21, 2008, 12:27:27 AM
With a quick glance I would say it can be converted to CBasic.

You'll just have to convert the window and control stuff from the EBasic way to the CBasic way.

Do as much as you can then post your error codes to get someone to help.

I'm working on my own programs and don't have time to convert it all for you.

Larry
Title: Re: Colorize text in real-time
Post by: aurelCB on August 21, 2008, 09:02:26 AM
Ok mr.Larry you right.
I'm just curius is this posible.And here is code wich i try convert but without sucsses.
I'm not good in functions -passing by reference or passing by values.Hmmm ...
maby someone can help....

'/*
'color code in rich edit control
'ibasic pro code
'jos de jong, 2007
'*/
'Creative code---->
'Declarations
'$INCLUDE "windows.inc"
CONST WM_USER = 0x400
CONST EM_FINDTEXT = (WM_USER + 56)
TYPE CHARRANGE
def cpMin:int
def cpMax:int
ENDTYPE
TYPE FINDTEXT
    def CHARRANGE :chrg
    def lpstrText:pointer
ENDTYPE

declare applyColorSheet(dlg:DIALOG,ctl:INT)
declare applyColorLine(dlg:DIALOG,ctl:INT)
declare RTFINDTEXT( w:DIALOG,ctl:INT,Searchtext:STRING,start_pos:INT,end_pos:INT,ignore_case:INT,match_word:INT), INT
'create a list with keywords
CONST kewordCount = 9
DEF keyword[kewordCount]:STRING
keyword[0] = "IF"
keyword[1] = "THEN"
keyword[2] = "ELSE"
keyword[3] = "ENDIF"
keyword[4] = "WHILE"
keyword[5] = "ENDWHILE"
keyword[6] = "DO"
keyword[7] = "FOR"
keyword[8] = "NEXT"

'_______________________________________________________________________
DEF d1:Dialog
DIALOG d1,0,0,587,360,0x80C80080,0,"Color code demo",Handler
CONTROL d1,"RE,,7,35,570,294,0x50B010C4,1"
DOMODAL d1
END


'______________________________________________________________________________
SUB Handler
SELECT @CLASS
'---------------------------------
CASE @IDINITDIALOG
CENTERWINDOW d1
'--------------------------------
'let the rich edit control send a message when the contents have changed
mask = CONTROLCMD(d1,1,@RTGETEVENTMASK)
CONTROLCMD d1, 1, @RTSETEVENTMASK, mask | @ENMKEYEVENTS |@ENMCHANGE

SETCONTROLTEXT d1, 1, "This program can highlight keywords like- IF THEN FOR NEXT "

applyColorSheet(d1, 1)

CASE @IDCONTROL
SELECT @CONTROLID
CASE 1:'richedit
SELECT @NOTIFYCODE
CASE @ENCHANGE
'the contents of the richedit are changed
' applyColorLine(d1, 1)
ENDSELECT
ENDSELECT

ENDSELECT
RETURN
'ENDSUB



'______________________________________________________________________________
'/*
'This function adjusts the colors of all lines in the sheet
'*/
SUB applyColorSheet(dlg,ctl)
def char_start, char_end:int
def linenum, linecount:int

'hide the selection and get the current caret position
CONTROLCMD dlg, ctl, @RTHIDESEL, 1
CONTROLCMD dlg, ctl, @RTGETSELECTION, char_start, char_end

linecount = CONTROLCMD(dlg, ctl, @RTGETLINECOUNT)
FOR linenum = 0 TO linecount-1
colorize(dlg, ctl, linenum)
NEXT linenum

'restore the original caret position and show the selection again
CONTROLCMD dlg, ctl, @RTSETSELECTION, char_start, char_end
CONTROLCMD dlg, ctl, @RTHIDESEL, 0

RETURN
'ENDSUB


'______________________________________________________________________________
'/*
'This function adjusts the colors of the current line
'*/
SUB applyColorLine(dlg,ctl)
def char_start, char_end:int
def linenum:int

'hide the selection and get the current caret position
CONTROLCMD dlg, ctl, @RTHIDESEL, 1
CONTROLCMD dlg, ctl, @RTGETSELECTION, char_start, char_end

linenum = CONTROLCMD (dlg, ctl, @RTLINEFROMCHAR, char_start)
colorize(dlg, ctl, linenum)

'restore the original caret position and show the selection again
CONTROLCMD dlg, ctl, @RTSETSELECTION, char_start, char_end
CONTROLCMD dlg, ctl, @RTHIDESEL, 0

RETURN
'ENDSUB

'______________________________________________________________________________
'/*
'This function adjusts the colors of the keywords on the given linenum
'*/
SUB colorize(dlg,ctl,linenum)
def lineStart, lineLength:int
def i:int
def p, pLine:int

lineStart = CONTROLCMD (dlg, ctl, @RTCHARFROMLINE, linenum)
lineLength = CONTROLCMD (dlg, ctl, @RTGETLINELENGTH, linenum)

'uncolor the whole line, set black color
CONTROLCMD dlg, ctl, @RTSETSELECTION, lineStart, lineStart + lineLength
CONTROLCMD dlg, ctl, @RTSETSELCOLOR, RGB(0, 0, 0)

'check the keywords one by one, if they occur on this line
FOR i=0 TO kewordCount-1
p = lineStart-1
DO
p = RTFINDTEXT(dlg, ctl, keyword[i], p+1, lineStart + lineLength, True, True)
IF p >= 0
'the keyword is found at the current line. color it
CONTROLCMD dlg, ctl, @RTSETSELECTION, p, p+LEN(keyword[i])
CONTROLCMD dlg, ctl, @RTSETSELCOLOR, RGB(255, 0, 0)

''you can also add making the text uppercase and things like that...
'CONTROLCMD dlg, ctl, @RTREPLACESEL, UCASE$(keyword[i])
ENDIF
UNTIL p < 0
NEXT i

RETURN
'ENDSUB


'________________________________________________________________________
SUB RTFINDTEXT(w:DIALOG,ctl:INT,Searchtext:STRING,start_pos:INT,end_pos:INT,ignore_case:INT,match_word:INT), INT
'Searches for the given searchtext, in characters from start_pos to end_pos.
'You can choose to select ignore_case and match_word. ignore_case=1-match_case
'Returns the position of the first found match. If there is no match, then returns -1
def pos:int
def flags:int
' >>> here i recive error message
FINDTEXT MyFindtext :' variable wrong type in line 166 <<<<
MyFindtext.chrg.cpMin = start_pos
MyFindtext.chrg.cpMax = end_pos
MyFindtext.lpstrText = Searchtext
flags = FR_MATCHCASE*(1-ignore_case) | FR_WHOLEWORD*match_word
pos = SENDMESSAGE(w, EM_FINDTEXT, flags, MyFindtext, ctl)

    RETURN pos
'ENDSUB
Title: Re: Colorize text in real-time
Post by: aurelCB on August 21, 2008, 02:26:18 PM
Another try but still dont work ???

'-------------------------------
'color code in rich edit control
'ibasic pro code
'jos de jong, 2007
'*/
'Creative code---->
'Declarations
'$INCLUDE "windows.inc"
CONST FR_WHOLEWORD = 0x2
CONST FR_MATCHCASE = 0x4
CONST WM_USER = 0x400
CONST EM_FINDTEXT = (WM_USER + 56)
TYPE CHARRANGE
def cpMin:int
def cpMax:int
ENDTYPE
TYPE FINDTEXT
    def chrg:CHARRANGE
    def lpstrText:pointer
    'def MyFindText:string
ENDTYPE
'i add this declared functions-maby is wrong here
declare applyColorSheet(dlg:DIALOG,ctl:INT)
declare applyColorLine(dlg:DIALOG,ctl:INT)
declare RTFINDTEXT( w:DIALOG,ctl:INT,Searchtext:STRING,start_pos:INT,end_pos:INT,ignore_case:INT,match_word:INT), INT
'create a list with keywords
CONST kewordCount = 9
DEF keyword[kewordCount]:STRING
keyword[0] = "IF"
keyword[1] = "THEN"
keyword[2] = "ELSE"
keyword[3] = "ENDIF"
keyword[4] = "WHILE"
keyword[5] = "ENDWHILE"
keyword[6] = "DO"
keyword[7] = "FOR"
keyword[8] = "NEXT"

'_______________________________________________________________________
DEF d1:Dialog
DIALOG d1,0,0,587,360,0x80C80080,0,"Color code demo",Handler
CONTROL d1,"RE,,7,35,570,294,0x50B010C4,1"
DOMODAL d1
END


'______________________________________________________________________________
SUB Handler
SELECT @CLASS
'---------------------------------
CASE @IDINITDIALOG
CENTERWINDOW d1
'--------------------------------
'let the rich edit control send a message when the contents have changed
mask = CONTROLCMD(d1,1,@RTGETEVENTMASK)
CONTROLCMD d1, 1, @RTSETEVENTMASK, mask | @ENMKEYEVENTS |@ENMCHANGE

SETCONTROLTEXT d1, 1, "This program can highlight keywords like- IF THEN FOR NEXT "

applyColorSheet(d1, 1)

CASE @IDCONTROL
SELECT @CONTROLID
CASE 1:'richedit
SELECT @NOTIFYCODE
CASE @ENCHANGE
'the contents of the richedit are changed
applyColorLine(d1, 1)
ENDSELECT
ENDSELECT
ENDSELECT
RETURN

'This function adjusts the colors of all lines in the sheet
SUB applyColorSheet(dlg,ctl)
def char_start, char_end:int
def linenum, linecount:int

'hide the selection and get the current caret position
CONTROLCMD dlg, ctl, @RTHIDESEL, 1
CONTROLCMD dlg, ctl, @RTGETSELECTION, char_start, char_end

linecount = CONTROLCMD(dlg, ctl, @RTGETLINECOUNT)
FOR linenum = 0 TO linecount-1
colorize(dlg, ctl, linenum)
NEXT linenum

'restore the original caret position and show the selection again
CONTROLCMD dlg, ctl, @RTSETSELECTION, char_start, char_end
CONTROLCMD dlg, ctl, @RTHIDESEL, 0

RETURN

'This function adjusts the colors of the current line
SUB applyColorLine(dlg,ctl)
def char_start, char_end:int
def linenum:int

'hide the selection and get the current caret position
CONTROLCMD dlg, ctl, @RTHIDESEL, 1
CONTROLCMD dlg, ctl, @RTGETSELECTION, char_start, char_end

linenum = CONTROLCMD (dlg, ctl, @RTLINEFROMCHAR, char_start)
colorize(dlg, ctl, linenum)

'restore the original caret position and show the selection again
CONTROLCMD dlg, ctl, @RTSETSELECTION, char_start, char_end
CONTROLCMD dlg, ctl, @RTHIDESEL, 0

RETURN

'This function adjusts the colors of the keywords on the given linenum
SUB colorize(dlg,ctl,linenum)
def lineStart, lineLength:int
def i,ctl,linenum:int
def p, pLine:int
lineStart = CONTROLCMD (d1, 1,@RTLINEFROMCHAR, linenum)
lineLength = CONTROLCMD (d1, 1, @RTGETLINELENGTH, linenum)

'uncolor the whole line, set black color
' CONTROLCMD dlg, ctl, @RTHIDESEL, 0
CONTROLCMD d1, 1, @RTSETSELECTION, lineStart, lineStart + lineLength
CONTROLCMD d1, 1, @RTSETSELCOLOR, RGB(0, 0, 0)

'check the keywords one by one, if they occur on this line
FOR i=0 TO kewordCount-1
p = lineStart-1
DO
p = RTFINDTEXT(dlg, ctl, keyword[i], p+1, lineStart + lineLength, True, True)
IF p >= 0
'the keyword is found at the current line. color it
CONTROLCMD dlg, ctl, @RTSETSELECTION, p, p+LEN(keyword[i])
CONTROLCMD dlg, ctl, @RTSETSELCOLOR, RGB(255, 0, 0)

''you can also add making the text uppercase and things like that...
'CONTROLCMD dlg, ctl, @RTREPLACESEL, UCASE$(keyword[i])
ENDIF
UNTIL p < 0
NEXT i
RETURN

SUB RTFINDTEXT(w:DIALOG,ctl:INT,Searchtext:STRING,start_pos:INT,end_pos:INT,ignore_case:INT,match_word:INT)
'Searches for the given searchtext, in characters from start_pos to end_pos.
'You can choose to select ignore_case and match_word. ignore_case=1-match_case
'Returns the position of the first found match. If there is no match, then returns -1
def w:dialog
def start_pos, end_pos,ctl:int
def Searchtext:string
def ignore_case:INT
def match_word:INT
def pos:int
def flags:int
'>>> here i recive error message
def Myfindtext:FINDTEXT:'variable wrong type in line 166 <<<<
MyFindtext.chrg.cpMin = start_pos
MyFindtext.chrg.cpMax = end_pos
MyFindtext.lpstrText = Searchtext
flags = FR_MATCHCASE*(1-ignore_case) | FR_WHOLEWORD*match_word
    'here i recive error now-variable wrong type in line 160
pos = SENDMESSAGE(d1, EM_FINDTEXT, flags, MyFindtext, ctl)

RETURN pos


any idea or maby someone know different way?
Title: Re: Colorize text in real-time
Post by: aurelCB on August 22, 2008, 07:08:17 AM
Hi again...
I made few changas and i got something but still dont work properly.
I replace @RTCHARFROMLINE to @RTLINEFROMCHAR ,i know that is wrong
but how replace (convert) this comand to CB
'-------------------------------------------------------------------------------------------------
   lineStart = CONTROLCMD (d1, 1,@RTLINEFROMCHAR, linenum)
   lineLength = CONTROLCMD (d1, 1, @RTGETLINELENGTH, linenum)
'-----------------------------------------------------------------------------------------------------
Also i disable function:
RTFINDTEXT( w:DIALOG,ctl:INT,Searchtext:STRING,start_pos:INT,end_pos:INT,ignore_case:INT,match_word:INT), INT

So here is code:

'-------------------------------
'color code in rich edit control
'ibasic pro code
'jos de jong, 2007
'*/
'Creative code---->
'Declarations
'$INCLUDE "windows.inc"
CONST FR_WHOLEWORD = 0x2
CONST FR_MATCHCASE = 0x4
CONST WM_USER = 0x400
CONST EM_FINDTEXT = (WM_USER + 56)
TYPE CHARRANGE
def cpMin:int
def cpMax:int
ENDTYPE
TYPE FINDTEXT
    def chrg:CHARRANGE
    def lpstrText:pointer
    'def MyFindText:string
ENDTYPE
'i add this declared functions-maby is wrong here
declare applyColorSheet(dlg:DIALOG,ctl:INT)
declare applyColorLine(dlg:DIALOG,ctl:INT)
'declare RTFINDTEXT( w:DIALOG,ctl:INT,Searchtext:STRING,start_pos:INT,end_pos:INT,ignore_case:INT,match_word:INT), INT
'create a list with keywords
CONST kewordCount = 9
DEF keyword[kewordCount]:STRING
keyword[0] = "IF"
keyword[1] = "THEN"
keyword[2] = "ELSE"
keyword[3] = "ENDIF"
keyword[4] = "WHILE"
keyword[5] = "ENDWHILE"
keyword[6] = "DO"
keyword[7] = "FOR"
keyword[8] = "NEXT"

'_______________________________________________________________________
DEF d1:Dialog
DIALOG d1,0,0,587,360,0x80C80080,0,"Color code demo",Handler
CONTROL d1,"RE,,7,35,570,294,0x50B010C4,1"
DOMODAL d1
END


'______________________________________________________________________________
SUB Handler
SELECT @CLASS
'---------------------------------
CASE @IDINITDIALOG
CENTERWINDOW d1
SETFONT d1, "Courier New", 10, 400,0,1
'--------------------------------
'let the rich edit control send a message when the contents have changed
mask = CONTROLCMD(d1,1,@RTGETEVENTMASK)
CONTROLCMD d1, 1, @RTSETEVENTMASK, mask | @ENMKEYEVENTS |@ENMCHANGE

SETCONTROLTEXT d1, 1, "This program can highlight keywords like- IF a THEN bi FOR  nil NEXT"

applyColorSheet(d1, 1)

CASE @IDCONTROL
SELECT @CONTROLID
CASE 1:'richedit
SELECT @NOTIFYCODE
CASE @ENCHANGE
'the contents of the richedit are changed
applyColorLine(d1, 1)
ENDSELECT
ENDSELECT
ENDSELECT
RETURN

'This function adjusts the colors of all lines in the sheet
SUB applyColorSheet(dlg,ctl)
def char_start, char_end:int
def linenum, linecount:int

'hide the selection and get the current caret position
CONTROLCMD dlg, ctl, @RTHIDESEL, 1
CONTROLCMD dlg, ctl, @RTGETSELECTION, char_start, char_end

linecount = CONTROLCMD(dlg, ctl, @RTGETLINECOUNT)
FOR linenum = 0 TO linecount-1
colorize(dlg, ctl, linenum)
NEXT linenum

'restore the original caret position and show the selection again
CONTROLCMD dlg, ctl, @RTSETSELECTION, char_start, char_end
CONTROLCMD dlg, ctl, @RTHIDESEL, 0

RETURN

'This function adjusts the colors of the current line
SUB applyColorLine(dlg,ctl)
def char_start, char_end:int
def linenum:int

'hide the selection and get the current caret position
CONTROLCMD dlg, ctl, @RTHIDESEL, 1
CONTROLCMD dlg, ctl, @RTGETSELECTION, char_start, char_end

linenum = CONTROLCMD (dlg, ctl, @RTLINEFROMCHAR, char_start)
colorize(dlg, ctl, linenum)

'restore the original caret position and show the selection again
CONTROLCMD dlg, ctl, @RTSETSELECTION, char_start, char_end
CONTROLCMD dlg, ctl, @RTHIDESEL, 0

RETURN

'This function adjusts the colors of the keywords on the given linenum
SUB colorize(dlg,ctl,linenum)
def lineStart, lineLength:int
def i,ctl,linenum:int
def p, pLine:int
' i replace @rtcharfromline to @RTLINEFROMCHAR ,i know that is wrong
' but how replace (convert) this comand to CB
lineStart = CONTROLCMD (d1, 1,@RTLINEFROMCHAR, linenum)
lineLength = CONTROLCMD (d1, 1, @RTGETLINELENGTH, linenum)

'uncolor the whole line, set black color
' CONTROLCMD dlg, ctl, @RTHIDESEL, 0
CONTROLCMD d1, 1, @RTSETSELECTION, lineStart, lineStart + lineLength
CONTROLCMD d1, 1, @RTSETSELCOLOR, RGB(0, 0, 0)

'check the keywords one by one, if they occur on this line
FOR i=0 TO kewordCount-1
p = lineStart-1
DO
'p = RTFINDTEXT(dlg, ctl, keyword[i], p+1, lineStart + lineLength, True, True)
' i change previus line to :
p = CONTROLCMD (d1, 1, @RTFINDTEXT,keyword[i] , p+1,lineStart + lineLength )

IF p > 0
'the keyword is found at the current line. color it
CONTROLCMD d1, 1, @RTSETSELECTION, p, p+LEN(keyword[i])
CONTROLCMD d1, 1, @RTSETSELCOLOR, RGB(255, 0, 0)

''you can also add making the text uppercase and things like that...
'CONTROLCMD dlg, ctl, @RTREPLACESEL, UCASE$(keyword[i])
ENDIF
UNTIL p < 0
NEXT i
RETURN

SUB RTFINDTEXT(w:DIALOG,ctl:INT,Searchtext:STRING,start_pos:INT,end_pos:INT,ignore_case:INT,match_word:INT)
'Searches for the given searchtext, in characters from start_pos to end_pos.
'You can choose to select ignore_case and match_word. ignore_case=1-match_case
'Returns the position of the first found match. If there is no match, then returns -1
def w:dialog
def start_pos, end_pos,ctl:int
def Searchtext:string
def ignore_case:INT
def match_word:INT
def pos:int
def flags:int
'>>> here i recive error message
def Myfindtext:FINDTEXT:'variable wrong type in line 166 <<<<
MyFindtext.chrg.cpMin = start_pos
MyFindtext.chrg.cpMax = end_pos
MyFindtext.lpstrText = Searchtext
flags = FR_MATCHCASE*(1-ignore_case) | FR_WHOLEWORD*match_word
    'here i recive error now-variable wrong type in line 160
pos = SENDMESSAGE(d1, EM_FINDTEXT,MyFindtext,0, 1)

RETURN pos


Any sugesstion???
Title: Re: Colorize text in real-time
Post by: LarryMc on August 22, 2008, 11:26:25 AM
I tried to solve the problem but was unsuccessful.
I'm not familiar with IBasic Standard or CBasic since I've never used them.

Larry
Title: Re: Colorize text in real-time
Post by: aurelCB on August 22, 2008, 12:50:10 PM
Thanks for your try mr.Larry :)
Title: Re: Colorize text in real-time
Post by: aurelCB on August 24, 2008, 12:39:48 PM
Uh finaly works....
Simple just add two lines of code and works properly!
regards
aurel ;)

'-------------------------------
'color code in rich edit control
'ibasic pro code
'original jos de jong, 2007
'Creative code ---->>>>>>>>>>>>>>>>>>>
declare applyColorSheet(d1:DIALOG,ctl:INT)
declare applyColorLine(d1:DIALOG,ctl:INT)
'create a list with keywords
CONST kewordCount = 9
DEF keyword[kewordCount]:STRING
keyword[0] = "IF"
keyword[1] = "THEN"
keyword[2] = "ELSE"
keyword[3] = "ENDIF"
keyword[4] = "WHILE"
keyword[5] = "ENDWHILE"
keyword[6] = "DO"
keyword[7] = "FOR"
keyword[8] = "NEXT"

'_______________________________________________________________________
DEF d1:Dialog
DIALOG d1,0,0,587,360,0x80C80080,0,"Color code demo",Handler
CONTROL d1,"RE,,7,35,570,294,0x50B010C4,1"
DOMODAL d1
END
'______________________________________________________________________________
SUB Handler
SELECT @CLASS
'---------------------------------
CASE @IDINITDIALOG
CENTERWINDOW d1
SETFONT d1, "Courier New", 10, 400,0,1
'--------------------------------
'let the rich edit control send a message when the contents have changed
mask = CONTROLCMD(d1,1,@RTGETEVENTMASK)
CONTROLCMD d1, 1, @RTSETEVENTMASK, mask | @ENMKEYEVENTS |@ENMCHANGE

SETCONTROLTEXT d1, 1, "This program FOR highlight keywords like"+chr$(13)+"IF ; THEN ; FOR ; NEXT"

applyColorSheet(d1, 1)

CASE @IDCONTROL
SELECT @CONTROLID
CASE 1:'richedit
SELECT @NOTIFYCODE
CASE @ENCHANGE
'the contents of the richedit are changed
applyColorLine(d1, 1)
ENDSELECT
ENDSELECT
ENDSELECT
RETURN

'This function adjusts the colors of all lines in the sheet
SUB applyColorSheet(d1,ctl)
def char_start, char_end:int
def linenum, linecount:int

'hide the selection and get the current caret position
CONTROLCMD d1, ctl, @RTHIDESEL, 1
CONTROLCMD d1, ctl, @RTGETSELECTION, char_start, char_end

linecount = CONTROLCMD(d1, ctl, @RTGETLINECOUNT)
messagebox d1,"Linecount= "+str$(linecount),"LCount"

FOR linenum = 0 TO linecount-1
colorize(d1, ctl, linenum)
NEXT linenum

'restore the original caret position and show the selection again
CONTROLCMD d1, ctl, @RTSETSELECTION, char_start, char_end
CONTROLCMD d1, ctl, @RTHIDESEL, 0

RETURN

'This function adjusts the colors of the current line
SUB applyColorLine(d1,ctl)
def char_start, char_end:int
def linenum:int

'hide the selection and get the current caret position
CONTROLCMD d1, ctl, @RTHIDESEL, 1
CONTROLCMD d1, ctl, @RTGETSELECTION, char_start,char_end

linenum = CONTROLCMD (d1, ctl, @RTLINEFROMCHAR, char_start)
colorize(d1, ctl, linenum)

'restore the original caret position and show the selection again
CONTROLCMD d1, ctl, @RTSETSELECTION, char_start, char_end
CONTROLCMD d1, ctl, @RTHIDESEL, 0

RETURN

'This function adjusts the colors of the keywords on the given linenum
SUB colorize(d1,ctl,linenum)
def lineStart, lineLength:int
def i,ctl,linenum,char_start:int
def p, pLine:int

' but how replace (convert) this comand to CB
lineStart = CONTROLCMD (d1, 1,char_start, linenum)
lineLength = CONTROLCMD (d1, 1, @RTGETLINELENGTH,linenum)

'uncolor the whole line, set black color
' CONTROLCMD dlg, ctl, @RTHIDESEL, 0
CONTROLCMD d1, 1, @RTSETSELECTION, lineStart, lineStart + lineLength
CONTROLCMD d1, 1, @RTSETSELCOLOR, RGB(0, 0, 0)

'check the keywords one by one, if they occur on this line
FOR i=0 TO kewordCount-1
p = lineStart+1
DO
'p = RTFINDTEXT(dlg, ctl, keyword[i], p+1, lineStart + lineLength, True, True)
' i change previus line to :
p = CONTROLCMD (d1, 1, @RTFINDTEXT,keyword[i] , p+1,p+LEN(keyword[i]) )

IF p > 0
'the keyword is found at the current line. color it
CONTROLCMD d1, 1, @RTSETSELECTION, p,p+LEN(keyword[i])
CONTROLCMD d1, 1, @RTSETSELCOLOR, RGB(255, 0, 0)
ENDIF

''you can also add making the text uppercase and things like that...
'CONTROLCMD dlg, ctl, @RTREPLACESEL, UCASE$(keyword[i])

UNTIL p < 0
'next two lines solve problem------------------------------------
CONTROLCMD d1, 1, @RTSETSELECTION, p,p-LEN(keyword[i])
CONTROLCMD d1, 1, @RTSETSELCOLOR, RGB(0, 0, 0)
'----------------------------------------------------------------
NEXT i
RETURN

Title: Re: Colorize text in real-time
Post by: aurelCB on August 26, 2008, 02:24:28 PM
Next example present colorized text in RichEdit control
wich is created in window not in dialog.
I'm think that work better in window becose there's no flickering when you start program.
I also add just one color for specific word.
regards
Aurel :)

'Sintax color in window
'Creative code---->
'Declarations
'declare applyColorSheet(d1:DIALOG,ctl:INT)
declare applyColorLine(w1:window,ctl:INT)
'create a list with keywords
CONST kewordCount = 12
DEF keyword[kewordCount]:STRING
keyword[0] = "IF"
keyword[1] = "THEN"
keyword[2] = "ELSE"
keyword[3] = "ENDIF"
keyword[4] = "WHILE"
keyword[5] = "ENDWHILE"
keyword[6] = "TO"
keyword[7] = "FOR"
keyword[8] = "NEXT"
keyword[9] = "PRINT"
keyword[10] = "START"
keyword[11] = "SUB"

DEF w1:window
Window w1,0,0,600,400,@minbox,0,"Color code in window",main
Setwindowcolor w1,rgb(231,222,231)

run=1
Waituntil run =0
Closewindow w1
END

SUB main
SELECT @CLASS
'---------------------------------
case @idclosewindow
run=0
case @idcreate
Centerwindow w1
CONTROL w1,"RE,,7,35,570,294,0x50B010C4,1"
SETFONT w1, "Courier New", 10, 400,0,1

'let the rich edit control send a message when the contents have changed
mask = CONTROLCMD(w1,1,@RTGETEVENTMASK)
CONTROLCMD w1, 1, @RTSETEVENTMASK, mask | @ENMKEYEVENTS |@ENMCHANGE
' put text in control
SETCONTROLTEXT w1, 1, ">>>start<<< SUB open()"

CASE @IDCONTROL
SELECT @CONTROLID
CASE 1:'richedit
SELECT @NOTIFYCODE
CASE @ENCHANGE
'the contents of the richedit are changed
applyColorLine(w1,1)
ENDSELECT
ENDSELECT
ENDSELECT
RETURN

'This function adjusts the colors of the current line
SUB applyColorLine(w1,ctl)
def char_start, char_end:int
def linenum:int

'hide the selection and get the current caret position
CONTROLCMD w1, 1, @RTHIDESEL, 1
CONTROLCMD w1, 1, @RTGETSELECTION, char_start, char_end

linenum = CONTROLCMD (w1, 1, @RTLINEFROMCHAR, char_start)
colorize(w1, 1, linenum)

'restore the original caret position and show the selection again
CONTROLCMD w1, 1, @RTSETSELECTION, char_start, char_end
CONTROLCMD w1, 1, @RTHIDESEL, 0

RETURN

'This function adjusts the colors of the keywords on the given linenum
SUB colorize(w1,ctl,linenum)
def lineStart, lineLength:int
def i,ctl,linenum,char_start:int
def p, pLine:int

' but how replace (convert) this comand to CB,i use variable
lineStart = CONTROLCMD (w1, 1,char_start, linenum)
lineLength = CONTROLCMD (w1, 1, @RTGETLINELENGTH, linenum)

'uncolor the whole line, set black color
' CONTROLCMD dlg, ctl, @RTHIDESEL, 0
CONTROLCMD w1, 1, @RTSETSELECTION, lineStart, lineStart + lineLength
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(0, 0, 0)

'check the keywords one by one, if they occur on this line
FOR i=0 TO kewordCount-1
p = lineStart-1
DO

p = CONTROLCMD (w1, 1, @RTFINDTEXT,keyword[i] , p+1,lineStart + lineLength )

IF p > 0
'the keyword is found at the current line. color it
CONTROLCMD w1, 1, @RTSETSELECTION, p, p+LEN(keyword[i])
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(0, 0, 250)

''you can also add making the text uppercase and things like that...
'i add second color(magenta) for SUB
if keyword[i]="SUB"
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(200, 0, 200)
'next line set every colorized keyword in upper case
CONTROLCMD w1, 1, @RTREPLACESEL, UCASE$(keyword[i])
endif
ENDIF
UNTIL p < 0

CONTROLCMD w1, 1, @RTSETSELECTION, p, p-LEN(keyword[i])
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(0, 0, 0)
NEXT i
RETURN

Title: Re: Colorize text in real-time
Post by: aurelCB on August 28, 2008, 02:43:23 PM
Next step look like real code editor.
I think that would be useful for many of us.
Copy next code in editor(press button Paste ) and tell me how look?

' >>>start<<< sintax color on
Def w1:WINDOW
Window w1, 0,0,400,300, @minbox ,0,"Sintax Color",main

run=1
Waituntil run=0
Closewindow w1
End

SUB main
Select @class
   Case @idclosewindow
      run=0
Endselect
RETURN

'Sintax color in window
'Creative code---->
'Declarations
def filename,ln,printer,filter:string
def file1:FILE
def buffer[32766]:ISTRING
filter = "CBasic files|*.cba|All Files|*.*||"
'declare applyColorSheet(d1:DIALOG,ctl:INT)
declare applyColorLine(w1:window,ctl:INT)
'create a list with keywords
CONST kewordCount = 28
DEF keyword[kewordCount]:STRING
keyword[0] = " IF "
keyword[1] = " THEN "
keyword[2] = " ELSE "
keyword[3] = " ENDIF "
keyword[4] = " WHILE "
keyword[5] = " ENDWHILE "
keyword[6] = " TO "
keyword[7] = " FOR "
keyword[8] = " NEXT "
keyword[9] = " PRINT "
keyword[10] = "RETURN"
keyword[11] = "SUB"
keyword[12] = "WINDOW "
keyword[13] = ":WINDOW"
keyword[14] = "DEF "
keyword[15] = "idclosewindow"
keyword[16] = "@"
keyword[17] = "WINDOW "
keyword[18] = "CLOSEWINDOW "
keyword[19] = "CLASS"
keyword[20] = "CASE"
keyword[21] = "SELECT"
keyword[22] = "COLOR"
keyword[23] = "SINTAX"
keyword[24] = "ENDSELECT"
keyword[25] = "minbox"
keyword[26] = "WAITUNTIL"
keyword[27] = "END"

DEF w1:window
Window w1,0,0,600,400,@minbox,0,"Color code in window",main
Setwindowcolor w1,rgb(231,222,231)
'--------------------------------------------
CONTROL w1,"B,Open,11,9,70,20,0x50000001,2"
SETFONT w1, "Courier New", 10, 400,0,2
CONTROL w1,"B,Save,101,9,70,20,0x50000001,3"
SETFONT w1, "Courier New", 10, 400,0,3
CONTROL w1,"B,Copy,180,9,70,20,0x50000001,4"
SETFONT w1, "Courier New", 10, 400,0,4
CONTROL w1,"B,Paste,260,9,70,20,0x50000001,5"
SETFONT w1, "Courier New", 10, 400,0,5

'--------------------------------
run=1
Waituntil run =0
Closewindow w1
END

SUB main
SELECT @CLASS
'---------------------------------
case @idclosewindow
run=0
case @idcreate
Centerwindow w1
CONTROL w1,"RE,,7,35,570,294,0x50B010C4,1"
SETFONT w1, "Courier New", 10, 400,0,1

'let the rich edit control send a message when the contents have changed
mask = CONTROLCMD(w1,1,@RTGETEVENTMASK)
CONTROLCMD w1, 1, @RTSETEVENTMASK, mask | @ENMKEYEVENTS |@ENMCHANGE
' put text in control
SETCONTROLTEXT w1, 1, "'>>>start<<< Sintax Color"

CASE @IDCONTROL
SELECT @CONTROLID
CASE 1:'richedit
SELECT @NOTIFYCODE
CASE @ENCHANGE
'the contents of the richedit are changed
applyColorLine(w1,1)
ENDSELECT

CASE 2:'open file
doopen()
CASE 3:'save file
dosave()
CASE 4:'copy
CONTROLCMD w1,1,@RTCOPY
CASE 5:'paste
CONTROLCMD w1,1,@RTPASTE

ENDSELECT
ENDSELECT
RETURN

'This function adjusts the colors of the current line
SUB applyColorLine(w1,ctl)
def char_start, char_end:int
def linenum:int

'hide the selection and get the current caret position
CONTROLCMD w1, 1, @RTHIDESEL, 1
CONTROLCMD w1, 1, @RTGETSELECTION, char_start, char_end

linenum = CONTROLCMD (w1, 1, @RTLINEFROMCHAR, char_start)
colorize(w1, 1, linenum)

'restore the original caret position and show the selection again
CONTROLCMD w1, 1, @RTSETSELECTION, char_start, char_end
CONTROLCMD w1, 1, @RTHIDESEL, 0

RETURN

'This function adjusts the colors of the keywords on the given linenum
SUB colorize(w1,ctl,linenum)
def lineStart, lineLength:int
def i,ctl,linenum,char_start:int
def p, pLine:int

' but how replace (convert) this comand to CB,i use variable
lineStart = CONTROLCMD (w1, 1,char_start, linenum)
lineLength = CONTROLCMD (w1, 1, @RTGETLINELENGTH, linenum)

'uncolor the whole line, set black color
' CONTROLCMD dlg, ctl, @RTHIDESEL, 0
CONTROLCMD w1, 1, @RTSETSELECTION, lineStart, lineStart + lineLength
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(0, 0, 0)

'check the keywords one by one, if they occur on this line
FOR i=0 TO kewordCount-1
p = lineStart-1
DO

p = CONTROLCMD (w1, 1, @RTFINDTEXT,keyword[i] , p+1,lineStart + lineLength )

IF p > 0
'the keyword is found at the current line. color it
CONTROLCMD w1, 1, @RTSETSELECTION, p, p+LEN(keyword[i])
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(0, 0, 250)
'CONTROLCMD w1, 1, @RTREPLACESEL, UCASE$(keyword[i])
''you can also add making the text uppercase and things like that...
'i add second color(magenta) for SUB
If keyword[i]="SUB"
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(200, 0, 0)
CONTROLCMD w1, 1, @RTREPLACESEL, UCASE$(keyword[i])
Endif

If keyword[i]="RETURN"
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(200, 0, 0)
CONTROLCMD w1, 1, @RTREPLACESEL, UCASE$(keyword[i])
Endif

If keyword[i]=":WINDOW"
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(250, 0, 0)
CONTROLCMD w1, 1, @RTREPLACESEL, UCASE$(keyword[i])
Endif

If keyword[i]="idclosewindow"
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(180,0,180)
'CONTROLCMD w1, 1, @RTREPLACESEL, UCASE$(keyword[i])
Endif

If keyword[i]="@"
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(180,0,180)
'CONTROLCMD w1, 1, @RTREPLACESEL, UCASE$(keyword[i])
Endif

If keyword[i]="WINDOW"
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(0,0,0)
'CONTROLCMD w1, 1, @RTREPLACESEL, UCASE$(keyword[i])
Endif

If keyword[i]="CLASS"
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(200,0,200)
'CONTROLCMD w1, 1, @RTREPLACESEL, UCASE$(keyword[i])
Endif

If keyword[i]="COLOR"
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(0,140,0)
'CONTROLCMD w1, 1, @RTREPLACESEL, UCASE$(keyword[i])
Endif

If keyword[i]="SINTAX"
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(0,140,0)
'CONTROLCMD w1, 1, @RTREPLACESEL, UCASE$(keyword[i])
Endif
If keyword[i]="minbox"
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(180,0,180)
'CONTROLCMD w1, 1, @RTREPLACESEL, UCASE$(keyword[i])
Endif

ENDIF
UNTIL p < 0

CONTROLCMD w1, 1, @RTSETSELECTION, p, p-LEN(keyword[i])
CONTROLCMD w1, 1, @RTSETSELCOLOR, RGB(0, 0, 0)
NEXT i
RETURN
'open file------------------------------------------
SUB doopen
filename = filerequest("Load File",w1,1)
if(len(filename) > 0)
buffer = ""
if( openfile(file1,filename,"R") = 0)
do
if(read(file1,ln) = 0)
if len(buffer) < (32766-257)
buffer = buffer + ln + chr$(13) + chr$(10)
endif
endif
until eof(file1)
closefile file1
setcontroltext w1,1,buffer
endif
endif
RETURN
'save file-------------------------------------
SUB dosave
filename = filerequest("Save File",w1,0,filter,"cba")
if(len(filename) > 0)
if(openfile(file1,filename,"W") = 0)
buffer = getcontroltext(w1,1)
GOSUB RemoveCR
write file1,buffer
closefile file1
endif
endif
RETURN
'-------------
SUB RemoveCR
def pos:INT
def buffer2[32766]:ISTRING
pos = INSTR(buffer,CHR$(13))
while(pos)
if(mid$(buffer,pos,1) = CHR$(13))
buffer2 = left$(buffer,pos-1)
buffer2 = buffer2 + mid$(buffer,pos+1)
buffer = buffer2
endif
pos = INSTR(pos+1,buffer,chr$(13))
endwhile
return


What you mean?
Title: Re: Colorize text in real-time
Post by: aurelCB on August 30, 2008, 11:45:40 AM
Without comment??OK.
I ask myself and others is this posible make faster,without external dll. or scintila engine
i mean writte directly in Creative- maby with in line assembly ??
Any idea?
regards
aurel :)
Title: Re: Colorize text in real-time
Post by: aurelCB on August 31, 2008, 01:16:23 PM
Hi again...
I ask you for little help of course if you have time.
I'm not satisfied with sintax color speed and i find old IBpro code with Scintila dll.
Here is original code wich work fine on EB:

window w

declare import, xmsg alias SendMessageA( wnd:uint, msg:uint, wp:uint, lp:pointer ),int
declare import, LoadLibrary alias LoadLibraryA( lp:string ),uint
declare import, FreeLibrary( hnd:uint )

const SCE_IB_DEFAULT = 0
const SCE_IB_LINECOMMENT = 1
const SCE_IB_BLOCKCOMMENT = 2
const SCE_IB_NUMBER = 3
const SCE_IB_KEYWORD = 4
const SCE_IB_TYPE = 5
const SCE_IB_SETID = 6
const SCE_IB_PREPROCESSOR = 7
const SCE_IB_STRING = 8
const SCE_IB_OPERATOR = 9
const SCE_IB_IDENTIFIER = 10
const SCE_IB_LABEL = 11
const SCE_IB_ASM = 12

const SCLEX_IBASIC = 40

const SCI_SETLEXER = 4001
const SCI_STYLESETFORE = 2051
const SCI_STYLESETBACK = 2052
const SCI_STYLECLEARALL = 2050
const SCI_SETKEYWORDS = 4005
const SCI_STYLESETFONT = 2056
const SCI_STYLESETSIZE = 2055

openwindow( w, 0, 0, 500, 500, @CAPTION|@SYSMENU, 0, "Scintilla", &handler )
setwindowcolor w,rgb(220,220,220)
uint hlibsci, hsci
hlibsci = LoadLibrary( "SciLexer.dll" )

hsci = controlex( w, "Scintilla", "", 0, 0, 400, 400, 0, 0, 1 )

xmsg( hsci, SCI_SETLEXER, SCLEX_IBASIC, 0 )

xmsg( hsci, SCI_STYLESETFORE, SCE_IB_DEFAULT, 0 )
xmsg( hsci, SCI_STYLESETBACK, SCE_IB_DEFAULT, 0xFFFFFF )
xmsg( hsci, SCI_STYLECLEARALL, 0, 0 )

for i = 0 to 12
xmsg( hsci, SCI_STYLESETFONT, i, "Courier New" )
xmsg( hsci, SCI_STYLESETSIZE, i, 10 )
next i

xmsg( hsci, SCI_SETKEYWORDS, 0, "if endif type endtype" )
xmsg( hsci, SCI_SETKEYWORDS, 1, "window uint wincolor dialog" )
xmsg( hsci, SCI_SETKEYWORDS, 2, "@caption @sysmenu @minbox" )
xmsg( hsci, SCI_SETKEYWORDS, 3, "$include $ifdef $ifndef $endif" )

xmsg( hsci, SCI_STYLESETFORE, SCE_IB_LINECOMMENT, 0x008800 )
xmsg( hsci, SCI_STYLESETFORE, SCE_IB_BLOCKCOMMENT, 0x008800 )
xmsg( hsci, SCI_STYLESETFORE, SCE_IB_NUMBER, 0x008888 )
xmsg( hsci, SCI_STYLESETFORE, SCE_IB_KEYWORD, 0x0000FF )
xmsg( hsci, SCI_STYLESETFORE, SCE_IB_TYPE, 0xFF0000 )
xmsg( hsci, SCI_STYLESETFORE, SCE_IB_SETID, 0xFF8800 )
xmsg( hsci, SCI_STYLESETFORE, SCE_IB_PREPROCESSOR, 0x000088 )
xmsg( hsci, SCI_STYLESETFORE, SCE_IB_STRING, 0x880088 )
xmsg( hsci, SCI_STYLESETFORE, SCE_IB_OPERATOR, 0x884400 )
xmsg( hsci, SCI_STYLESETFORE, SCE_IB_IDENTIFIER, 0x000000 )
xmsg( hsci, SCI_STYLESETFORE, SCE_IB_LABEL, 0xAAAAAA )
xmsg( hsci, SCI_STYLESETFORE, SCE_IB_ASM, 0x555555 )

waituntil w.hwnd = 0
FreeLibrary( hlibsci )
end

sub handler

select @CLASS
case @IDCLOSEWINDOW
closewindow w
endselect

return
endsub


So i try convert this code to Creative but dont work.
I mean that i'm forget or miss something i realy dont know?
Maby is not posible becose CB dont support comand CONTROLEX??
I add this files in samples folder:SciLexer.dll(1.6.8.0),LexIBasic(CXXfile),scintilla.map file.

Here is my attempt:
def w:window

declare "kernel32.dll",xmsg alias SendMessageA( wnd:int, msg:int, wp:int, lp:pointer ),int
declare "kernel32.dll",LoadLibrary alias  LoadLibraryA( lp:string ),int
declare "kernel32.dll", FreeLibrary( hnd:int )

const controlex = 0x50B010C4

const SCE_IB_DEFAULT = 0
const SCE_IB_LINECOMMENT = 1
const SCE_IB_BLOCKCOMMENT = 2
const SCE_IB_NUMBER = 3
const SCE_IB_KEYWORD = 4
const SCE_IB_TYPE = 5
const SCE_IB_SETID = 6
const SCE_IB_PREPROCESSOR = 7
const SCE_IB_STRING = 8
const SCE_IB_OPERATOR = 9
const SCE_IB_IDENTIFIER = 10
const SCE_IB_LABEL = 11
const SCE_IB_ASM = 12

const SCLEX_IBASIC = 40

const SCI_SETLEXER = 4001
const SCI_STYLESETFORE = 2051
const SCI_STYLESETBACK = 2052
const SCI_STYLECLEARALL = 2050
const SCI_SETKEYWORDS = 4005
const SCI_STYLESETFONT = 2056
const SCI_STYLESETSIZE = 2055

def i:int
window w, 0, 0, 600, 480, @CAPTION|@SYSMENU, 0, "Scintilla", handler
setwindowcolor w,rgb(220,220,220)
def hlibsci, hsci:int

messagebox w,"Library Loaded : "+str$(hlibsci),"SciLib":'befor loading
hlibsci = LoadLibrary( "SciLexer.dll" )
messagebox w,"Library Loaded : "+str$(hlibsci),"SciLib":'after loading

'hsci =
control w,"RE,Scintila, 0, 0, 450, 400,0x50B010C4, 1"


'CONTROL w,"RE,,58,49,379,251,0x50B010C4,1"
'{return = } SENDMESSAGE ( window | dialog, msg, wparam, lparam {,ID} )
'''hsci=SendMessageA( wnd:int, msg:int, wp:int, lp:pointer )
'xmsg( hsci, SCI_SETLEXER, SCLEX_IBASIC, 0 )
hsci=SENDMESSAGE(w,SCI_SETLEXER, SCLEX_IBASIC, 0,1)
hsci=SENDMESSAGE (w, SCI_STYLESETFORE, SCE_IB_DEFAULT, 0 ,1)
hsci=SENDMESSAGE (w, SCI_STYLESETBACK, SCE_IB_DEFAULT, 0xFFFFFF,1 )
hsci=SENDMESSAGE (w, SCI_STYLECLEARALL, 0, 0,1)


for i = 0 to 12
hsci=SENDMESSAGE (w,SCI_STYLESETFONT, i, "Courier New",1 )
hsci=SENDMESSAGE (w, SCI_STYLESETSIZE, i, 10 ,1)
next i

hsci=SENDMESSAGE(w,SCI_SETKEYWORDS, 0, "if endif type endtype" ,1):'red
hsci=SENDMESSAGE(w, SCI_SETKEYWORDS, 1, "window setfont wincolor let ",1 ):'blue
hsci=SENDMESSAGE(w,SCI_SETKEYWORDS, 2, "@idcontrol @sysmenu @minbox",1 ):'lightblue
hsci=SENDMESSAGE(w, SCI_SETKEYWORDS, 3, "$include $ifndef $endif",1 ):'brown

hsci=SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_LINECOMMENT, 0x008800 ,1)
hsci=SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_BLOCKCOMMENT, 0x008800,1 )
hsci=SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_NUMBER, 0x008888,1)
hsci=SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_KEYWORD, 0x0000FF ,1)
hsci=SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_TYPE, 0xFF0000,1 )
hsci=SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_SETID, 0xFF8800 ,1)
hsci=SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_PREPROCESSOR, 0x000088 ,1)
hsci=SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_STRING, 0x880088 ,1)
hsci=SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_OPERATOR, 0x884400 ,1)
hsci=SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_IDENTIFIER, 0x000000 ,1)
hsci=SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_LABEL, 0xAAAAAA ,1)
hsci=SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_ASM, 0x555555 ,1)

waituntil w.hwnd = 0
FreeLibrary( hlibsci )
end

sub handler

select @CLASS
case @IDCLOSEWINDOW
closewindow w

endselect

return
'endsub


So what you mean ,what is wrong?

Title: Re: Colorize text in real-time
Post by: aurelCB on September 01, 2008, 02:34:10 PM
Hi where are you ....
Is it posible replace command CONTROLEX with some else or
create rich edit control from api.
I search and search but nothing usegful.
So every help will be OK :)
Title: Re: Colorize text in real-time
Post by: sapero on September 01, 2008, 03:00:19 PM
Hi Zlatko, you can use CreateWindowEx function:
DECLARE "user32.dll", CreateWindowExA(dwExStyle:INT, lpClassName:STRING, lpWindowName:STRING, dwStyle:INT, x:INT, y:INT, nWidth:INT, nHeight:INT, hWndParent:INT, hMenu:INT, hInstance:INT, lpParam:INT),INT
DECLARE "kernel32", GetModuleHandleA(name:INT),INT

' replace controlex with
hsci = CreateWindowExA(0, "Scintilla", "hello winapi", 0x50000000, 0,0,400,400,w,1, GetModuleHandleA(0), 0)
' WS_CHILD | WS_VISIBLE = 0x50000000


EDIT: changed POINTER to INT
Title: Re: Colorize text in real-time
Post by: aurelCB on September 02, 2008, 01:11:26 AM
Hi Sapero
But i now recive error message for this replaced line
" Argument wrong type on line"
in this line:
hsci = CreateWindowExA(0, "Scintilla", "hello winapi", 0x50000000, 0,0,400,400,w,1, GetModuleHandleA(0), 0)
I dont understand wich argument have wrong type?
Title: Re: Colorize text in real-time
Post by: sapero on September 02, 2008, 03:38:27 AM
I'm surprised, you need to change the type POINTER to INT in both imported functions. Or just define a pointer variable, set it to zero and replace zero's with it where should be a pointer.
def null:pointer
null=0

GetModuleHandleA(null)
CreateWindowEx(..., null)

Updated my post.
Title: Re: Colorize text in real-time
Post by: aurelCB on September 02, 2008, 07:24:05 AM
Hi Sapero i try this too but still dont work.
I find an old example by Larry Adcock called Tab.In this example i find diferent shape of
CreateWindowExA function:
declare "user32",CreateWindowExA(ex:int,class:string,name:string,style:int,x:int,y:int,x1:int,y1:int,parent:window,id:int,hinstance:int,ed:int),int
I try this and i got scintilla editor on window.Here is code:
def w:window
setid "WS_VISIBLE",&H10000000
setid "WS_CHILD",&H40000000
def null:pointer
null=0
declare "user32",CreateWindowExA(ex:int,class:string,name:string,style:int,x:int,y:int,x1:int,y1:int,parent:window,id:int,hinstance:int,ed:int),int
'DECLARE "user32.dll", CreateWindowExA(dwExStyle:INT, lpClassName:STRING, lpWindowName:STRING, dwStyle:INT, x:INT, y:INT, nWidth:INT, nHeight:INT, hWndParent:INT, hMenu:INT, hInstance:INT, lpParam:INT),INT
DECLARE "kernel32", GetModuleHandleA(name:null),INT
'  declare CreateRichControl(parent:pointer,x:int,y:int,w:int,ht:int)
'def null:pointer
'null=0
'--------------------------------------------------------------------------------------
' replace controlex with
'hsci = CreateWindowExA(0, "Scintilla", "hello winapi", 0x50000000, 0,0,400,400,w,1, GetModuleHandleA(0), 0)
' WS_CHILD | WS_VISIBLE = 0x50000000
'declare "user32",CreateWindowExA(ex:int,class:string,name:string,style:int,x:int,y:int,x1:int,y1:int,parent:window,id:int,hinstance:int,ed:int),int
declare "user32.dll",xmsg alias SendMessageA( wnd:int, message:int, wparam:int, lparam:pointer ),int
declare "kernel32",LoadLibrary alias  LoadLibraryA( lp:string ),int
declare "kernel32", FreeLibrary( hnd:int )



const SCE_IB_DEFAULT = 0
const SCE_IB_LINECOMMENT = 1
const SCE_IB_BLOCKCOMMENT = 2
const SCE_IB_NUMBER = 3
const SCE_IB_KEYWORD = 4
const SCE_IB_TYPE = 5
const SCE_IB_SETID = 6
const SCE_IB_PREPROCESSOR = 7
const SCE_IB_STRING = 8
const SCE_IB_OPERATOR = 9
const SCE_IB_IDENTIFIER = 10
const SCE_IB_LABEL = 11
const SCE_IB_ASM = 12

const SCLEX_IBASIC = 40

const SCI_SETLEXER = 4001
const SCI_STYLESETFORE = 2051
const SCI_STYLESETBACK = 2052
const SCI_STYLECLEARALL = 2050
const SCI_SETKEYWORDS = 4005
const SCI_STYLESETFONT = 2056
const SCI_STYLESETSIZE = 2055

def i:int
window w, 0, 0, 600, 480, @CAPTION|@SYSMENU, 0, "Scintilla", handler
setwindowcolor w,rgb(220,220,220)
def hlibsci, hsci:uint


hlibsci = LoadLibrary( "SciLexer.dll" )
messagebox w,"Library Loaded : "+str$(hlibsci),"SciLib":'after loading
'///original code///////////////////////////////////////////////////
'hsci = controlex( w, "Scintilla", "", 0, 0, 400, 400, 0, 0, 1 )

'// by sapero ////////////////////////////////////////////////////////
'const  WS_CHILD | WS_VISIBLE = 0x50000000
hsci=CreateWindowExA(0,"scintilla","",0x50000000,0,0,400,400,w,0,0,1)
'hsci = CreateWindowExA(0, "scintilla", "",0x50000000 ,0,0,400,400,w,0, 0)
'WS_CHILD | WS_VISIBLE = 0x50000000
'control w,"RE,Scintila, 0, 0, 450, 400,0x50B010C4, 1"
'hsci = CreateWindowExA(0, "Scintilla", "hello winapi", 0x50000000, 0,0,400,400,w,1, GetModuleHandleA(null), null)

'temp=SendMessage(hWnd,4875,0,0)
hsci=SENDMESSAGE(w,SCI_SETLEXER, SCLEX_IBASIC, 1)
hsci=SENDMESSAGE (w,SCI_STYLESETFORE, SCE_IB_DEFAULT,1 )
hsci=SENDMESSAGE (w,SCI_STYLESETBACK, SCE_IB_DEFAULT, 0xFFFFFF )
hsci=SENDMESSAGE (w,SCI_STYLECLEARALL, 0, 1)


for i = 0 to 12
hsci=SENDMESSAGE (w,SCI_STYLESETFONT, i, "Courier New" )
hsci=SENDMESSAGE (w,SCI_STYLESETSIZE, i, 10 )
next i

hsci=SENDMESSAGE(SCI_SETKEYWORDS, 0,1, "if endif type endtype" ):'red
hsci=SENDMESSAGE( SCI_SETKEYWORDS, 1,1, "window setfont wincolor let " ):'blue
hsci=SENDMESSAGE(SCI_SETKEYWORDS, 2,1, "@idcontrol @sysmenu @minbox" ):'lightblue
hsci=SENDMESSAGE( SCI_SETKEYWORDS, 3,1, "$include $ifndef $endif" ):'brown

hsci=SENDMESSAGE(SCI_STYLESETFORE, SCE_IB_LINECOMMENT, 0x008800,1 )
hsci=SENDMESSAGE(SCI_STYLESETFORE, SCE_IB_BLOCKCOMMENT, 0x008800,1 )
hsci=SENDMESSAGE(SCI_STYLESETFORE, SCE_IB_NUMBER, 0x008888,1)
hsci=SENDMESSAGE(SCI_STYLESETFORE, SCE_IB_KEYWORD, 0x0000FF,1)
hsci=SENDMESSAGE(SCI_STYLESETFORE, SCE_IB_TYPE, 0xFF0000 ,1)
hsci=SENDMESSAGE(SCI_STYLESETFORE, SCE_IB_SETID, 0xFF8800,1 )
hsci=SENDMESSAGE(SCI_STYLESETFORE, SCE_IB_PREPROCESSOR, 0x000088 ,1)
hsci=SENDMESSAGE(SCI_STYLESETFORE, SCE_IB_STRING, 0x880088,1 )
hsci=SENDMESSAGE(SCI_STYLESETFORE, SCE_IB_OPERATOR, 0x884400 ,1)
hsci=SENDMESSAGE(SCI_STYLESETFORE, SCE_IB_IDENTIFIER, 0x000000,1 )
hsci=SENDMESSAGE(SCI_STYLESETFORE, SCE_IB_LABEL, 0xAAAAAA ,1)
hsci=SENDMESSAGE(SCI_STYLESETFORE, SCE_IB_ASM, 0x555555,1 )

waituntil w.hwnd = 0
Freelibrary (hlibsci)
end

sub handler

select @CLASS
case @IDCLOSEWINDOW
closewindow w

endselect

return
'endsub
sub CreateRichControl(parent:pointer,x:int,y:int,w:int,ht:int)
def hWnd:int
declare "user32",CreateWindowExA(ex:int,class:string,name:string,style:int,x:int,y:int,x1:int,y1:int,parent:window,id:int,hinstance:int,ed:int),int
hWnd=CreateWindowExA(0,"scintilla","",&H10000000 | &H40000000,x,y,w,ht,#parent,2024+num,0,0)
clear CreateWindowExA
return hWnd


Last Sub is from larry code wich represent Tabs i change name to CreateRichControl original is
CreateTabControl((parent:pointer,x:int,y:int,w:int,ht:int)

Ok i finaly add control on window but how work with SENDMESSAGE command?
CBasic suport this shape of SendMessage :
{return = } SENDMESSAGE ( window | dialog, msg, wparam, lparam {,ID} )
i use this:
hsci=SENDMESSAGE(w,SCI_SETLEXER, SCLEX_IBASIC, 1)
if i do diferent like this:
hsci=SENDMESSAGE(w,SCI_SETLEXER, SCLEX_IBASIC,0, 1) --,i recive error message
"Control not found on line:"
I dont anderstand why,becose must be:
w=window,SCI_SETLEXER=msg,SCLEX_IBASIC=wparam,0=lparam and 1 is ID
Very confusing  ???
So my question is how send  messages to scintilla???

 
Title: Re: Colorize text in real-time
Post by: sapero on September 02, 2008, 08:48:53 AM
The problem is: you need to add 2024 to control ID inside CreateWindowEx:
def w:window
def null:pointer
null=0
declare "user32",CreateWindowExA(ex:int,class:string,name:string,style:int,x:int,y:int,x1:int,y1:int,parent:window,id:int,hinstance:int,ed:int),int
DECLARE "kernel32", GetExeHandle alias GetModuleHandleA(name:int),INT
declare "user32.dll",xmsg alias SendMessageA(wnd:int, message:int, wparam:int, lparam:pointer ),int
declare "kernel32", LoadLibrary alias  LoadLibraryA( lp:string ),int
declare "kernel32", FreeLibrary( hnd:int )

const SCE_IB_DEFAULT = 0
const SCE_IB_LINECOMMENT = 1
const SCE_IB_BLOCKCOMMENT = 2
const SCE_IB_NUMBER = 3
const SCE_IB_KEYWORD = 4
const SCE_IB_TYPE = 5
const SCE_IB_SETID = 6
const SCE_IB_PREPROCESSOR = 7
const SCE_IB_STRING = 8
const SCE_IB_OPERATOR = 9
const SCE_IB_IDENTIFIER = 10
const SCE_IB_LABEL = 11
const SCE_IB_ASM = 12

const SCLEX_IBASIC = 40

const SCI_SETLEXER = 4001
const SCI_STYLESETFORE = 2051
const SCI_STYLESETBACK = 2052
const SCI_STYLECLEARALL = 2050
const SCI_SETKEYWORDS = 4005
const SCI_STYLESETFONT = 2056
const SCI_STYLESETSIZE = 2055

def i:int
window w, 0, 0, 600, 480, @CAPTION|@SYSMENU, 0, "Scintilla", handler
setwindowcolor w,rgb(220,220,220)
def hlibsci, hsci:uint

const IDC_SCI = 100
const IDC_SCI_CREATE = 2024+IDC_SCI

hlibsci = LoadLibrary( "SciLexer.dll" )

hsci=CreateWindowExA(0,"scintilla","",0x50000000,0,0,400,400,w,IDC_SCI_CREATE,GetExeHandle(0),0)

SENDMESSAGE(w, SCI_SETLEXER, SCLEX_IBASIC, 1, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_DEFAULT,100, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETBACK, SCE_IB_DEFAULT, 0xFFFFFF, IDC_SCI)
SENDMESSAGE(w, SCI_STYLECLEARALL, 0, 1, IDC_SCI)

for i = 0 to 12
SENDMESSAGE (w, SCI_STYLESETFONT, i, "Courier New", IDC_SCI)
SENDMESSAGE (w, SCI_STYLESETSIZE, i, 10, IDC_SCI)
next i

SENDMESSAGE(w, SCI_SETKEYWORDS, 0,"if endif type endtype", IDC_SCI ):'red
SENDMESSAGE(w, SCI_SETKEYWORDS, 1,"window setfont wincolor let ", IDC_SCI ):'blue
SENDMESSAGE(w, SCI_SETKEYWORDS, 2,"@idcontrol @sysmenu @minbox", IDC_SCI ):'lightblue
SENDMESSAGE(w, SCI_SETKEYWORDS, 3,"$include $ifndef $endif", IDC_SCI ):'brown

SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_LINECOMMENT, 0x008800, IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_BLOCKCOMMENT, 0x008800, IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_NUMBER, 0x008888, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_KEYWORD, 0x0000FF, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_TYPE, 0xFF0000, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_SETID, 0xFF8800, IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_PREPROCESSOR, 0x000088, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_STRING, 0x880088, IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_OPERATOR, 0x884400, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_IDENTIFIER, 0x000000, IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_LABEL, 0xAAAAAA, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_ASM, 0x555555, IDC_SCI )
SetControlText w, IDC_SCI, "endtype window @minbox $include 0123 #ifstr _asm //comment"

waituntil w.hwnd = 0
Freelibrary (hlibsci)
end


sub handler
select @CLASS
case @IDCLOSEWINDOW
closewindow w
endselect
return
Title: Re: Colorize text in real-time
Post by: aurelCB on September 02, 2008, 09:57:40 AM
Yes you right Larry use same 2024 number in his example i miss this.
WOW finaly works ;D
Thank you very much Sapero, you are real expert ;)
regards
zlatko
Title: Re: Colorize text in real-time
Post by: aurelCB on October 06, 2008, 12:05:49 PM
Hi...
Just one question if you have time.
Scintilla work fine but how can i activate line numbering?
thanks advance...
zlatko
Title: Re: Colorize text in real-time
Post by: sapero on October 06, 2008, 12:33:07 PM
const SCI_SETMARGINWIDTHN = 2242
SENDMESSAGE(w, SCI_SETMARGINWIDTHN, 0, 40, IDC_SCI)

The zero is for margin index; SC_MARGIN_SYMBOL
Title: Re: Colorize text in real-time
Post by: aurelCB on October 07, 2008, 04:57:42 AM
Thanks again :)
Title: Re: Colorize text in real-time
Post by: aurelCB on October 08, 2008, 12:49:38 AM
Hi ...
I finaly understand that all action with scintilla.dll work with SANDMESSAGE command.
And i find scintilla command list.

Begin Const
SC_CASE_LOWER=2
SC_CASE_MIXED=0
SC_CASE_UPPER=1
SCE_B_ASM =14
SCE_B_COMMENT =1
SCE_B_CONSTANT =13
SCE_B_DATE =8
SCE_B_DEFAULT =0
SCE_B_IDENTIFIER =7
SCE_B_KEYWORD =3
SCE_B_KEYWORD2 =10
SCE_B_KEYWORD3 =11
SCE_B_KEYWORD4 =12
SCE_B_NUMBER =2
SCE_B_OPERATOR =6
SCE_B_PREPROCESSOR =5
SCE_B_STRING =4
SCE_B_STRINGEOL =9
SCI_ADDTEXT=2001
SCI_BRACEBADLIGHT=2352
SCI_BRACEHIGHLIGHT=2351
SCI_BRACEMATCH=2353
SCI_CANPASTE=2173
SCI_CANREDO=2016
SCI_CANUNDO=2174
SCI_CLEAR=2180
SCI_CLEARALL=2004
SCI_COLOURISE=4003
SCI_COPY=2178
SCI_CUT=2177
SCI_EMPTYUNDOBUFFER=2175
SCI_FINDTEXT=2150
SCI_GETCARETLINEBACK=2097
SCI_GETCARETLINEVISIBLE=2095
SCI_GETCHARAT=2007
SCI_GETCOLUMN=2129
SCI_GETCURRENTPOS=2008
SCI_GETINDENT=2123
SCI_GETINDENTATIONGUIDES=2133
SCI_GETLENGTH=2006
SCI_GETLEXER=4002
SCI_GETLINECOUNT=2154
SCI_GETLINEINDENTATION=2127
SCI_GETMARGINWIDTHN=2243
SCI_GETMODIFY=2159
SCI_GETSEARCHFLAGS =2199
SCI_GETSELECTIONEND=2145
SCI_GETSELECTIONSTART=2143
SCI_GETTARGETEND= 2193
SCI_GETTARGETSTART= 2191
SCI_GETTEXT=2182
SCI_GETTEXTLENGTH=2183
SCI_GETUSETABS=2125
SCI_GETVIEWEOL=2355
SCI_GETVIEWWS=2020
SCI_GETWRAPMODE=2269
SCI_GETZOOM=2374
SCI_GOTOLINE=2024
SCI_GOTOPOS=2025
SCI_INSERTTEXT=2003
SCI_LINEFROMPOSITION=2166
SCI_PASTE=2179
SCI_POSITIONFROMLINE=2167
SCI_REDO=2011
SCI_REPLACETARGET= 2194
SCI_REPLACETARGETRE =2195
SCI_SCROLLCARET=2169
SCI_SEARCHINTARGET= 2197
SCI_SELECTALL=2013
SCI_SETCARETFORE=2069
SCI_SETCARETLINEBACK=2098
SCI_SETCARETLINEVISIBLE=2096
SCI_SETCURRENTPOS=2141
SCI_SETINDENT=2122
SCI_SETINDENTATIONGUIDES=2132
SCI_SETKEYWORDS=4005
SCI_SETLEXER=4001
SCI_SETLEXERLANGUAGE=4006
SCI_SETLINEINDENTATION=2126
SCI_SETMARGINWIDTHN=2242
SCI_SETPROPERTY=4004
SCI_SETSAVEPOINT=2014
SCI_SETSEARCHFLAGS =2198
SCI_SETSELBACK=2068
SCI_SETSELECTIONEND=2144
SCI_SETSELECTIONSTART=2142
SCI_SETSELFORE=2067
SCI_SETTARGETEND= 2192
SCI_SETTARGETSTART= 2190
SCI_SETTEXT=2181
SCI_SETUSETABS=2124
SCI_SETVIEWEOL=2356
SCI_SETVIEWWS=2021
SCI_SETWRAPMODE=2268
SCI_SETZOOM=2373
SCI_STYLESETBACK =2052
SCI_STYLESETBOLD =2053
SCI_STYLESETCASE=2060
SCI_STYLESETFONT =2056
SCI_STYLESETFORE =2051
SCI_STYLESETITALIC =2054
SCI_STYLESETSIZE =2055
SCI_TARGETFROMSELECTION=2287
SCI_UNDO=2176
SCI_USEPOPUP=2371
SCI_ZOOMIN=2333
SCI_ZOOMOUT=2334
SCLEX_CPP=3
SCLEX_HTML=4
SCLEX_NULL=1
SCLEX_PERL=6
SCLEX_PYTHON=2
SCLEX_SQL=7
SCLEX_VB=8
SCLEX_XML=5
SCN_UPDATEUI=2007
End Const


For example is this command SCI_GETLINECOUNT=2154 same as  @RTGETLINECOUNT
and wich command replace @RTGETLINE ?
I only found here SCI_GETTEXT=2182 ?
Without this two commands i can do anything what i need.
thanks advance
zlatko
zlatko
Title: Re: Colorize text in real-time
Post by: sapero on October 08, 2008, 01:56:40 AM
Zlatko, download my headers pak, install it to any directory (like temp) and search in /include/scintilla.inc for SCI_GETLINE, or anything you need. There is also scilexer include.
To replace selection or insert text, use the @EDREPLACESEL / EM_REPLACESEL edit control command. Some edit commands are still supported in scintilla.
Title: Re: Colorize text in real-time
Post by: aurelCB on October 08, 2008, 07:46:49 AM
Hi Sapero...
I do like you said-download headers for EBasic and find scintilla in iclude folder.
Excellent stuff.
SCI_GETLINECOUNT work fine but SCI_GETLINE dont ,just crush Cbasic or
i recive error message Illegal Assignment on line 109.Where is the cach?

def w:window
DEF abscript[32766]:ISTRING
DEF start,smax:INT
DEF text:string
def null:pointer
null=0
declare "user32",CreateWindowExA(ex:int,class:string,name:string,style:int,x:int,y:int,x1:int,y1:int,parent:window,id:int,hinstance:int,ed:int),int
DECLARE "kernel32", GetExeHandle alias GetModuleHandleA(name:int),INT
declare "user32.dll",xmsg alias SendMessageA(wnd:int, message:int, wparam:int, lparam:pointer ),int
declare "kernel32", LoadLibrary alias  LoadLibraryA( lp:string ),int
declare "kernel32", FreeLibrary( hnd:int )

const SCE_IB_DEFAULT = 0
const SCE_IB_LINECOMMENT = 1
const SCE_IB_BLOCKCOMMENT = 2
const SCE_IB_NUMBER = 3
const SCE_IB_KEYWORD = 4
const SCE_IB_TYPE = 5
const SCE_IB_SETID = 6
const SCE_IB_PREPROCESSOR = 7
const SCE_IB_STRING = 8
const SCE_IB_OPERATOR = 9
const SCE_IB_IDENTIFIER = 10
const SCE_IB_LABEL = 11
const SCE_IB_ASM = 12
const SCI_MARGIN_SYMBOL = 2227

const SCLEX_IBASIC = 30

const SCI_SETLEXER = 4001
const SCI_STYLESETFORE = 2051
const SCI_STYLESETBACK = 2052
const SCI_STYLECLEARALL = 2050
const SCI_SETKEYWORDS = 4005
const SCI_STYLESETFONT = 2056
const SCI_STYLESETSIZE = 2055
const SCI_SETMARGINWIDTHN = 2242
'const SCI_GETLINECOUNT=2154
const SCI_GETLINE = 2153
const SCI_GETLINECOUNT = 2154

def i:int
Window w, 0, 0, 600, 480, @minbox, 0, "Scintilla based editor", handler
'menu
MENU w,"T,File,0,0","I,New,0,11","I,Open,0,7","I,Save,0,6","I,Exit,0,1"
INSERTMENU w,1,"T,Edit,0,0","I,Undo,0,2","I,Cut,0,3","I,Copy,0,4","I,Paste,0,5"
INSERTMENU w,2,"T,Execute,0,0","I,Run Script,0,8"
INSERTMENU w,3,"T,Build,0,0","I,Start Build,0,22"
INSERTMENU w,4,"T,Help,0,0","I,Help,0,9","I,About,0,21"
setwindowcolor w,rgb(220,220,230)
def hlibsci, hsci:int

const IDC_SCI = 100
const IDC_SCI_CREATE = 2024+IDC_SCI

hlibsci = LoadLibrary( "SciLexer.dll" )
'create RichEdit Scintilla control-replace CONTROLEX command from EBasic
hsci=CreateWindowExA(0,"scintilla","",0x50000000|@border,10,30,570,390,w,IDC_SCI_CREATE,GetExeHandle(0),0)

SENDMESSAGE(w, SCI_SETLEXER, SCLEX_IBASIC, 1, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_DEFAULT,100, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETBACK, SCE_IB_DEFAULT, 0xFFFFFF, IDC_SCI)
SENDMESSAGE(w, SCI_STYLECLEARALL, 0, 1, IDC_SCI)

for i = 0 to 12
SENDMESSAGE (w, SCI_STYLESETFONT, i, "Courier New", IDC_SCI)
SENDMESSAGE (w, SCI_STYLESETSIZE, i, 10, IDC_SCI)
next i

SENDMESSAGE(w, SCI_SETKEYWORDS, 0,"wait defnum defstr closewin", IDC_SCI ):'red
SENDMESSAGE(w, SCI_SETKEYWORDS, 1,"win setfont wincolor let", IDC_SCI ):'blue
SENDMESSAGE(w, SCI_SETKEYWORDS, 2,"circle rect line pixel", IDC_SCI ):'lightblue
SENDMESSAGE(w, SCI_SETKEYWORDS, 3,"sub endsub text clear$", IDC_SCI ):'brown
'next line set margin for line numbers (40 is Lparam)
SENDMESSAGE(w, SCI_SETMARGINWIDTHN, 0, 40, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_LINECOMMENT, 0x008800, IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_BLOCKCOMMENT, 0x008800, IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_NUMBER, 0x555555, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_KEYWORD, 0x0000FF, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_TYPE, 0xFF0000, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_SETID,rgb(245,127,0), IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_PREPROCESSOR, 0x000088, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_STRING, 0x880088, IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_OPERATOR, 0x884400, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_IDENTIFIER, 0x000000, IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_LABEL, 0xAAAAAA, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_ASM, 0x555555, IDC_SCI )
'SetControlText w, IDC_SCI, "endtype window @minix $include 0123 #ifstr _asm //comment"
'setfocus w

waituntil w.hwnd = 0
Freelibrary (hlibsci)
end


sub handler
select @CLASS
case @IDCLOSEWINDOW
closewindow w

CASE @IDMENUPICK
SELECT @MENUNUM
CASE 8:'Quit
start=1
'recive message from scintila-number of written lines in control
smax = Sendmessage ( w, SCI_GETLINECOUNT,0,smax,IDC_SCI )
messagebox w,"GetLineCount:"+str$(smax),"Message from control"
'recive message from scintila - get script line-error illegal assignment on line
abscript[start] =Sendmessage( w, SCI_GETLINE ,0,abscript[start],IDC_SCI)
messagebox w,"Get Script :"+abscript[start],"Message from control"


ENDSELECT
endselect
return
Title: Re: Colorize text in real-time
Post by: sapero on October 08, 2008, 09:01:24 AM
Sendmessage( w, SCI_GETLINE ,0,abscript,IDC_SCI)
messagebox w,"Get Script :"+abscript,"Message from control"


Say, how would you write string into single character? -> abscript[start]
http://scintilla.sourceforge.net/ScintillaDoc.html#SCI_GETLINE
Title: Re: Colorize text in real-time
Post by: aurelCB on October 08, 2008, 12:11:47 PM
Hi Sapero this is original code without scintilla:
def w:window
DEF abscript[32766]:STRING
DEF start,smax:INT
DEF text:string


def i:int
Window w, 0, 0, 600, 480, @minbox, 0, "Without Scintilla", handler
Setwindowcolor w,rgb(220,220,230)
'menu
MENU w,"T,File,0,0","I,New,0,11","I,Open,0,7","I,Save,0,6","I,Exit,0,1"
INSERTMENU w,1,"T,Edit,0,0","I,Undo,0,2","I,Cut,0,3","I,Copy,0,4","I,Paste,0,5"
INSERTMENU w,2,"T,Execute,0,0","I,Run Script,0,8"
INSERTMENU w,3,"T,Build,0,0","I,Start Build,0,22"
INSERTMENU w,4,"T,Help,0,0","I,Help,0,9","I,About,0,21"
Setwindowcolor w,rgb(220,220,230)
CONTROL w,"RE,,10,10,570,390,0x50B010C4,1"
SETFONT w,"Courier New",10, 400,0,1
'-------------------------------
SETCONTROLTEXT w, 1,"Zero Line" +chr$(10)+"First Line"+chr$(10)+"Second Line"




waituntil w = 0
end


sub handler
select @CLASS
case @IDCLOSEWINDOW
closewindow w

CASE @IDMENUPICK
SELECT @MENUNUM
CASE 8:'Quit
start=2
'recive message from scintila-number of written lines in control
smax = CONTROLCMD ( w, 1, @RTGETLINECOUNT )
smax=smax-1:'down by one
messagebox w,"GetLineCount:"+str$(smax),"Message from control"
'recive message from scintila - get script line-error illegal assignment on line
abscript[start] = CONTROLCMD( w,1, @rtgetline ,start)
messagebox w,"Get Script :"+ abscript[start],"Code from control"


ENDSELECT
endselect
return


And here is finaly working example with scintilla.
I do not know that SCI_GETLINE need different shape of SENDMESSAGE ,i think that is same like
SCI_GETLINECOUNT.
Problem with start is solved ,variable start must be Wparam and string abscript[start] is Lparam.
def w:window
DEF abscript[32766]:STRING
DEF start,smax:INT
DEF text:string
'def null:pointer
'null=0
declare "user32",CreateWindowExA(ex:int,class:string,name:string,style:int,x:int,y:int,x1:int,y1:int,parent:window,id:int,hinstance:int,ed:int),int
DECLARE "kernel32", GetExeHandle alias GetModuleHandleA(name:int),INT
'declare "user32.dll",xmsg alias SendMessageA(wnd:int, message:int, wparam:int, lparam:pointer ),int
declare "kernel32", LoadLibrary alias  LoadLibraryA( lp:string ),int
declare "kernel32", FreeLibrary( hnd:int )

const SCE_IB_DEFAULT = 0
const SCE_IB_LINECOMMENT = 1
const SCE_IB_BLOCKCOMMENT = 2
const SCE_IB_NUMBER = 3
const SCE_IB_KEYWORD = 4
const SCE_IB_TYPE = 5
const SCE_IB_SETID = 6
const SCE_IB_PREPROCESSOR = 7
const SCE_IB_STRING = 8
const SCE_IB_OPERATOR = 9
const SCE_IB_IDENTIFIER = 10
const SCE_IB_LABEL = 11
const SCE_IB_ASM = 12
const SCI_MARGIN_SYMBOL = 2227

const SCLEX_IBASIC = 30

const SCI_SETLEXER = 4001
const SCI_STYLESETFORE = 2051
const SCI_STYLESETBACK = 2052
const SCI_STYLECLEARALL = 2050
const SCI_SETKEYWORDS = 4005
const SCI_STYLESETFONT = 2056
const SCI_STYLESETSIZE = 2055
const SCI_SETMARGINWIDTHN = 2242
'const SCI_GETLINECOUNT=2154
const SCI_GETLINE = 2153
const SCI_GETLINECOUNT = 2154
const SCI_GETCURLINE= 2027

def i:int
Window w, 0, 0, 600, 480, @minbox, 0, "Scintilla based editor", handler
'menu
MENU w,"T,File,0,0","I,New,0,11","I,Open,0,7","I,Save,0,6","I,Exit,0,1"
INSERTMENU w,1,"T,Edit,0,0","I,Undo,0,2","I,Cut,0,3","I,Copy,0,4","I,Paste,0,5"
INSERTMENU w,2,"T,Execute,0,0","I,Run Script,0,8"
INSERTMENU w,3,"T,Build,0,0","I,Start Build,0,22"
INSERTMENU w,4,"T,Help,0,0","I,Help,0,9","I,About,0,21"
setwindowcolor w,rgb(220,220,230)
def hlibsci, hsci:int

const IDC_SCI = 100
const IDC_SCI_CREATE = 2024+IDC_SCI

hlibsci = LoadLibrary( "SciLexer.dll" )
'create RichEdit Scintilla control-replace CONTROLEX command from EBasic
hsci=CreateWindowExA(0,"scintilla","",0x50000000|@border,10,30,570,390,w,IDC_SCI_CREATE,GetExeHandle(0),0)

SENDMESSAGE(w, SCI_SETLEXER, SCLEX_IBASIC, 1, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_DEFAULT,100, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETBACK, SCE_IB_DEFAULT, 0xFFFFFF, IDC_SCI)
SENDMESSAGE(w, SCI_STYLECLEARALL, 0, 1, IDC_SCI)

for i = 0 to 12
SENDMESSAGE (w, SCI_STYLESETFONT, i, "Courier New", IDC_SCI)
SENDMESSAGE (w, SCI_STYLESETSIZE, i, 10, IDC_SCI)
next i

SENDMESSAGE(w, SCI_SETKEYWORDS, 0,"wait defnum defstr closewin", IDC_SCI ):'red
SENDMESSAGE(w, SCI_SETKEYWORDS, 1,"win setfont wincolor let", IDC_SCI ):'blue
SENDMESSAGE(w, SCI_SETKEYWORDS, 2,"circle rect line pixel", IDC_SCI ):'lightblue
SENDMESSAGE(w, SCI_SETKEYWORDS, 3,"sub endsub text clear$", IDC_SCI ):'brown
'next line set margin for line numbers (40 is Lparam)
SENDMESSAGE(w, SCI_SETMARGINWIDTHN, 0, 40, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_LINECOMMENT, 0x008800, IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_BLOCKCOMMENT, 0x008800, IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_NUMBER, 0x555555, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_KEYWORD, 0x0000FF, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_TYPE, 0xFF0000, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_SETID,rgb(245,127,0), IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_PREPROCESSOR, 0x000088, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_STRING, 0x880088, IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_OPERATOR, 0x884400, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_IDENTIFIER, 0x000000, IDC_SCI )
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_LABEL, 0xAAAAAA, IDC_SCI)
SENDMESSAGE(w, SCI_STYLESETFORE, SCE_IB_ASM, 0x555555, IDC_SCI )

SETCONTROLTEXT w, IDC_SCI,"Zero Line" +chr$(10)+"First Line"+chr$(10)+"Second Line"
'setfocus w

waituntil w.hwnd = 0
Freelibrary (hlibsci)
end


sub handler
select @CLASS
case @IDCLOSEWINDOW
closewindow w

CASE @IDMENUPICK
SELECT @MENUNUM
CASE 8:'Quit
'recive message from scintila-number of written lines in control
smax = Sendmessage ( w, SCI_GETLINECOUNT,1,smax,IDC_SCI )
messagebox w,"GetLineCount:"+str$(smax),"Message from control"
'retrive zero based index
start=smax-1:'start is 2
'send message to scintila - get text line
Sendmessage( w, SCI_GETLINE ,start,abscript[start],IDC_SCI)
messagebox w,"Get Script :"+ abscript[start],"Script from control"


ENDSELECT
endselect
return

Thanks again,and i learn something new! :)
regards
zlatko
Title: Re: Colorize text in real-time
Post by: aurelCB on September 27, 2009, 06:55:34 AM
Hi ...
I know that this topic is little bit old.
But one thing bugging me.
I dont know which command in scintilla create field on the right side of line numbers .
This field I need for markers.

Any advice...?
Thanks advance

Aurel
Title: Re: Colorize text in real-time
Post by: sapero on September 27, 2009, 08:04:29 AM
It's a margin, use SCI_SETMARGINWIDTHN. There may be up to 5 margins.
Title: Re: Colorize text in real-time
Post by: aurelCB on September 27, 2009, 08:29:48 AM
Thanks Sapero....
But how add second margin becose i already have one for numbers?
Title: Re: Colorize text in real-time
Post by: sapero on September 27, 2009, 08:56:12 AM
5 margins are there, you need to resize one:sendmessage(win, SCI_SETMARGINWIDTHN, margin_index, width, controlid)
If you set width to zero, the margin will be not visible. Please also read scintilla documentation http://scintilla.sourceforge.net/ScintillaDoc.html#SCI_SETMARGINWIDTHN
Title: Re: Colorize text in real-time
Post by: aurelCB on September 27, 2009, 10:02:01 AM
Ufff...
I read scintilal doc and must be work but not.Thanks for link...
I currently have this:
'const SC_MARGIN_SYMBOL = 0
'const SC_MARGIN_NUMBER = 1

SendMessage(w1,SCI_SETMARGINTYPEN,0,SC_MARGIN_NUMBER,IDC_SCI)
SendMessage(w1,SCI_SETMARGINTYPEN,2,SC_MARGIN_SYMBOL,IDC_SCI)

SendMessage(w1,SCI_SETMARGINMASKN,2,2,IDC_SCI)
SendMessage(w1,SCI_SETMARGINWIDTHN,0,40,IDC_SCI)
SendMessage(w1,SCI_SETMARGINWIDTHN,2,24,IDC_SCI)
    SendMessage(w1,SCI_SETFOLDMARGINCOLOUR,1,rgb(00,00,0),IDC_SCI)
'makers --------------------------------------------------
    'SendMessage(w1, SCI_MARKERDELETEALL, 2 ,0,IDC_SCI)
'SendMessage(w1, SCI_MARKERADD, 1, 0,IDC_SCI)
    SendMessage(w1, SCI_MARKERDEFINE, 2, SC_MARK_SHORTARROW,IDC_SCI )
SendMessage(w1, SCI_MARKERSETFORE, 2, RGB(80,0,0),IDC_SCI)
SendMessage(w1, SCI_MARKERSETBACK, 2, RGB(255,0,0),IDC_SCI)

SendMessage(w1, SCI_MARKERADD, 2, 0,IDC_SCI)


Exactly same order of using messages have one C++ example wich i find on 'Code Project' page.
But this dont work.I also try same thing in Free Basic and also dont work.Weird...
Title: Re: Colorize text in real-time
Post by: aurelCB on September 28, 2009, 12:14:02 PM
Hi ...
I finaly get one part of problem.I find scintilla example on PureBasic forum
which explain how add next margin for marker but
marker still is not visible :-[
here is right part which open second margin:
; Margins PB
SendMessage(w1, SCI_SETMARGINTYPEN, 0, SC_MARGIN_NUMBER,IDC_SCI)
SendMessage(w1, SCI_SETMARGINMASKN, 2, SC_MASK_FOLDERS,IDC_SCI)
SendMessage(w1, SCI_SETMARGINWIDTHN, 0, 40,IDC_SCI)
SendMessage(w1, SCI_SETMARGINWIDTHN, 2, 20,IDC_SCI)
SendMessage(w1, SCI_SETMARGINSENSITIVEN, 2, 1,IDC_SCI)


And just is missing part for properly add marker to margin...
Title: Re: Colorize text in real-time
Post by: sapero on September 28, 2009, 12:46:00 PM
Aurel, if you expect to have fast and accurate reply, you need to be precise with your questions. I have posted some examples with scintilla control, configured to display VisualStudio like markers. Go to Aurora forum and search for CHM maker. Download the zip, and open the mdichild.src file. Scroll down to InitMdiChild subroutine, and find this:data->sci->SetMarginTypeN(0, SC_MARGIN_NUMBER)In next two lines I'm just presetting width of two margins (SetMarginWidthN) and finally is a call to SciInitFolding subroutine, where all the markers are defined. Do not follow InitHtmlSyntax subroutine because it sets only language specific keywords.
You just need to convert each line:
aurora: sci->MarkerDefine (SC_MARKNUM_FOLDEROPEN, SC_MARK_BOXMINUS);
cbasic: SendMessage(w1, SCI_MarkerDefine, SC_MARKNUM_FOLDEROPEN, SC_MARK_BOXMINUS, controlID)

in other words:
convert sci->X(Y, Z);
to SendMessage(w1, SCI_X, Y, Z, IDC_SCI)

Title: Re: Colorize text in real-time
Post by: aurelCB on September 28, 2009, 12:52:45 PM
Sapero you are the man....like always i completly forget for your CHM maker. :-[
Of course i have latest version.
Sorry if i'm not quite precise about question(language beriere always bugging me ::)).
Yes this is great replay. ;)
Thanks a lot...
Title: Re: Colorize text in real-time
Post by: aurelCB on September 28, 2009, 01:11:31 PM
Sorry Sapero if i bothering you but your suggestion like:
SendMessage(w1, SCI_MarkerDefine, 0, SC_MARKNUM_FOLDEROPEN, SC_MARK_BOXMINUS, controlID)
Make error : Wrong  number of arguments!
In PB code i see something like this:
; Choose folding icons
Scintilla(sciptr, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEROPEN, #SC_MARK_CIRCLEMINUS)

and this:
; Choose folding icon colours
Scintilla(sciptr, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDER, $FFFFFF)


But dont worry i will find the way(I hope),must work... 8)
Title: Re: Colorize text in real-time
Post by: sapero on September 28, 2009, 01:30:10 PM
Yup, sorry for the additional 0, updated!
Title: Re: Colorize text in real-time
Post by: aurelCB on September 30, 2009, 04:56:57 AM
No problem...for that
But i'm really confusing.
I study again your code in CHM maker and PB code and scintilla doc.
I dont wanna margin with folding style i need margin with markers such a arrow,roundrect and
similiar for point to errors in line.
So i dont understand which scintilla command show marker in margin.
I ceate nonfolding margin like scintila doc says and try add marker on line 1 with SCI_MARKERADD
but without sucsess?
; Margins PB
SendMessage(w1, SCI_SETMARGINTYPEN, 0, SC_MARGIN_NUMBER,IDC_SCI)
SendMessage(w1, SCI_SETMARGINWIDTHN, 0, 46,IDC_SCI)
SendMessage(w1, SCI_SETMARGINTYPEN, 1, SC_MARGIN_SYMBOL,IDC_SCI)
SendMessage(w1, SCI_SETMARGINWIDTHN, 1, 20,IDC_SCI)
SendMessage(w1, SCI_SETMARGINMASKN, 1, SC_MASK_FOLDERS,IDC_SCI)


'SendMessage(w1, SCI_SETMARGINWIDTHN, 1,1,IDC_SCI):' hide margine 1 if visible


SendMessage(w1, SCI_MARKERDEFINE,1,SC_MARK_ROUNDRECT,IDC_SCI )
SendMessage(w1, SCI_MARKERADD, 1,1 ,IDC_SCI)
SendMessage(w1, SCI_MARKERADDSET, 1,SC_MASK_FOLDERS ,IDC_SCI)
'SendMessage(w1, SCI_MARKERDELETEALL,0,0,IDC_SCI)
Title: Re: Colorize text in real-time
Post by: sapero on September 30, 2009, 05:59:05 AM
Zlatko, try this:SendMessage(w1, SCI_SETMARGINTYPEN, 0, SC_MARGIN_NUMBER, IDC_SCI)
SendMessage(w1, SCI_SETMARGINWIDTHN, 0, 20, IDC_SCI)

SendMessage(w1, SCI_SETMARGINTYPEN, 1, SC_MARGIN_SYMBOL, IDC_SCI)
SendMessage(w1, SCI_SETMARGINWIDTHN, 1, 16, IDC_SCI)

' define markers - SCI_MARKERDEFINE(markerindex, markertype)
SendMessage(w1, SCI_MARKERDEFINE, 0, SC_MARK_CIRCLE, IDC_SCI) ' SC_MARK_CIRCLE is default
SendMessage(w1, SCI_MARKERDEFINE, 1, SC_MARK_ROUNDRECT, IDC_SCI)
SendMessage(w1, SCI_MARKERDEFINE, 2, SC_MARK_ARROW, IDC_SCI)

' marker colors - SCI_MARKERSETFORE(markerindex, color)
' SCI_MARKERSETBACK(markerindex, color)
SendMessage(w1, SCI_MARKERSETBACK, 0, rgb(0,0,255), IDC_SCI)

' add markers - SCI_MARKERADD(line, markerindex)
SendMessage(w1, SCI_MARKERADD, 0, 0, IDC_SCI)
SendMessage(w1, SCI_MARKERADD, 1, 1, IDC_SCI)
SendMessage(w1, SCI_MARKERADD, 2, 2, IDC_SCI)

' remove marker 2 from line 2 - SCI_MARKERDELETE(line, markerindex)
'SendMessage(w1, SCI_MARKERDELETE, 2, 2, IDC_SCI)
Title: Re: Colorize text in real-time
Post by: aurelCB on September 30, 2009, 06:53:59 AM
WOW....
Excellent Sapero.!!!!!!!!!!
I really dont know what we can do here without your help?
Thank you very much!

And here is my example(I finaly figured how work ::)):

; Margins ////////////////////////////////////////////////////////
'set number margin (for numnbers)
SendMessage(w1, SCI_SETMARGINTYPEN, 0, SC_MARGIN_NUMBER,IDC_SCI)
SendMessage(w1, SCI_SETMARGINWIDTHN, 0, 40,IDC_SCI)
'set symbol margin (for markers)
SendMessage(w1, SCI_SETMARGINTYPEN, 1, SC_MARGIN_SYMBOL,IDC_SCI)
SendMessage(w1, SCI_SETMARGINWIDTHN, 1, 20,IDC_SCI)

'define markers
SendMessage(w1, SCI_MARKERDEFINE,0,SC_MARK_CIRCLE,IDC_SCI )
SendMessage(w1, SCI_MARKERDEFINE,1,SC_MARK_ROUNDRECT,IDC_SCI )
SendMessage(w1, SCI_MARKERDEFINE,2,SC_MARK_ARROW,IDC_SCI)

'set marker 0 - circle - backcolor
SendMessage(w1, SCI_MARKERSETBACK, 0, RGB(0,150,0),IDC_SCI)
'set marker 1 - roundrect - backcolor
SendMessage(w1, SCI_MARKERSETBACK, 1, RGB(0,0,255),IDC_SCI)
'set marker 2 - arrow - backcolor
SendMessage(w1, SCI_MARKERSETBACK, 2, RGB(255,0,0),IDC_SCI)

'set marker to first position (zero position/empty editor/)show red arrow marker
SendMessage(w1, SCI_MARKERADD, 0,2 ,IDC_SCI)


Aurel
Title: Re: Colorize text in real-time
Post by: tbohon on February 17, 2010, 08:04:17 AM
Aurel:

Finally got some time to 'play around' with the Scintilla controls using your last working example above as a starting point.

When I try to compile in CBasic I get an error re: missing control for this line:

SENDMESSAGE(w, SCI_SETLEXER, SCLEX_IBASIC, 1, IDC_SCI)

What library/libraries are you using with this program?

Remember this is all new to me (CBasic anyway) so be gentle ... :)

Tnx.

Tom
Title: Re: Colorize text in real-time
Post by: aurelCB on February 17, 2010, 10:15:23 AM
Hi Tom.

you probably miss this:
const IDC_SCI = 100
const IDC_SCI_CREATE = 2024+IDC_SCI


and then

def hlibsci, hsci:int
hlibsci = LoadLibrary( "SciLexer.dll" )
'create sci control
hsci=CreateWindowExA(0x20000,"Scintilla","",0x50010000,sciLw,sciTw,sciWidth,sciHeight,w1,IDC_SCI_CREATE,GetExeHandle(0),0)
Title: Re: Colorize text in real-time
Post by: tbohon on February 17, 2010, 07:44:32 PM
Gee, I get having those lines would help a bit, eh?

;)

Thanks.
Title: Re: Colorize text in real-time
Post by: aurelCB on February 18, 2010, 12:09:10 AM
Tom
Heh i'm not sure exactly what you need.
Here is the scintilla constants which i use :
const SCE_IB_DEFAULT = 0
const SCE_IB_LINECOMMENT = 1
const SCE_IB_BLOCKCOMMENT = 2
const SCE_IB_NUMBER = 3
const SCE_IB_KEYWORD = 4
const SCE_IB_TYPE = 5
const SCE_IB_SETID = 6
const SCE_IB_PREPROCESSOR = 7
const SCE_IB_STRING = 8
const SCE_IB_OPERATOR = 9
const SCE_IB_IDENTIFIER = 10
const SCE_IB_LABEL = 11
const SCE_IB_ASM = 12
'---------------------------------------
const SCLEX_ABASIC = 40
'const SCLEX_VB=8
'---------------------------------------
const SCI_SETLEXER = 4001
const SCI_STYLESETFORE = 2051
const SCI_STYLESETBACK = 2052
const SCI_STYLECLEARALL = 2050
const SCI_SETKEYWORDS = 4005
const SCI_STYLESETFONT = 2056
const SCI_STYLESETSIZE = 2055
const SCI_SETMARGINWIDTHN = 2242
const SCI_SETMARGINTYPEN = 2240
const SCI_SETMARGINSENSITIVEN = 2246
const SCI_SETSELBACK = 2068
const SCI_GOTOLINE = 2024
const SCI_GETLINE = 2153
const SCI_GETLINECOUNT = 2154
const SCI_GETCURLINE= 2027
const SCI_SCROLLCARET=2169
const SCI_GOTOPOS=2025

const SCI_CLEAR=2180
const SCI_CLEARALL=2004
const SCI_BRACEBADLIGHT=2352
const SCI_BRACEHIGHLIGHT=2351
const SCI_BRACEMATCH=2353
const SCI_GETSELECTIONEND=2145
const SCI_GETTEXTLENGTH = 2183
const SCI_GETTEXT = 2182
const SCI_SETSELECTIONEND=2144
const SCI_SETCARETLINEVISIBLE=2096
const SCI_UNDO = 2176
const SCI_CUT = 2177
const SCI_COPY = 2178
const SCI_PASTE = 2179


'open main window here ---------------------------------------------------------------
--------------------------------------------------------------------------------------------------

And i create scintilla control under @idcreate:
CASE @IDCREATE

'-----------------------------------------------------------------------------------------
def hlibsci, hsci:int
hlibsci = LoadLibrary( "SciLexer.dll" )
'create sci control
hsci=CreateWindowExA(0x20000,"Scintilla","",0x50010000,sciLw,sciTw,sciWidth,sciHeight,w1,IDC_SCI_CREATE,GetExeHandle(0),0)

SENDMESSAGE(w1, SCI_SETLEXER, SCLEX_ABASIC, 1, IDC_SCI)
SENDMESSAGE(w1, SCI_STYLESETFORE, SCE_IB_DEFAULT,100, IDC_SCI)
SENDMESSAGE(w1, SCI_STYLESETBACK,32,rgb(255,255,250), IDC_SCI)
SENDMESSAGE(w1, SCI_STYLECLEARALL, 0, 1, IDC_SCI)

For i = 0 to 12
SENDMESSAGE (w1, SCI_STYLESETFONT, i, "Courier New", IDC_SCI)
SENDMESSAGE (w1, SCI_STYLESETSIZE, i, 9, IDC_SCI)
Next i

SENDMESSAGE(w1, SCI_SETKEYWORDS, 0, scired , IDC_SCI ):'red
SENDMESSAGE(w1, SCI_SETKEYWORDS, 1, sciblue , IDC_SCI ):'blue
SENDMESSAGE(w1, SCI_SETKEYWORDS, 2, scidblue ,IDC_SCI):'darkblue
SENDMESSAGE(w1, SCI_SETKEYWORDS, 3,"winhigh winwide clearspace text msgbox ", IDC_SCI ):'brown
SENDMESSAGE(w1, SCI_STYLESETFORE, SCE_IB_LINECOMMENT, 0x007F00, IDC_SCI )
SENDMESSAGE(w1, SCI_STYLESETFORE, SCE_IB_BLOCKCOMMENT, 0x008800, IDC_SCI )
SENDMESSAGE(w1, SCI_STYLESETFORE, SCE_IB_NUMBER, 0x555555, IDC_SCI)
SENDMESSAGE(w1, SCI_STYLESETFORE, SCE_IB_KEYWORD, 0x0000FF, IDC_SCI)
SENDMESSAGE(w1, SCI_STYLESETFORE, SCE_IB_TYPE, 0xFF0000, IDC_SCI)
SENDMESSAGE(w1, SCI_STYLESETFORE, SCE_IB_SETID,rgb(0,0,175), IDC_SCI ):'orange/to dark blue
SENDMESSAGE(w1, SCI_STYLESETFORE, SCE_IB_PREPROCESSOR, 0x000088, IDC_SCI)
SENDMESSAGE(w1, SCI_STYLESETFORE, SCE_IB_STRING, 0x880088, IDC_SCI )
SENDMESSAGE(w1, SCI_STYLESETFORE, SCE_IB_OPERATOR, 0x884400, IDC_SCI)
SENDMESSAGE(w1, SCI_STYLESETFORE, SCE_IB_IDENTIFIER, 0x000000, IDC_SCI )
SENDMESSAGE(w1, SCI_STYLESETFORE, SCE_IB_LABEL, 0xAAAAAA, IDC_SCI)
SENDMESSAGE(w1, SCI_STYLESETFORE, SCE_IB_ASM, 0x555555, IDC_SCI )
CENTERWINDOW w1


I hope that now you understand better