Oh...from timo...all right, I've downloaded it right now but I've not opened the zip file *lol* but anyway...can you help me with this?
you know...that code works very good! but when I try to use a For...Next look to check for my own keywords (for now I'm using the keywords that the SyntaxHighlighting.pb uses) it doesn't work
....sorry for asking too much...
Code: Select all
Declare HighlightLine(Line)
Declare WindowCallback(hWnd, uMsg, wParam, lParam)
Declare InitSyntaxHighlightning()
Dim ValidCharacters.b(255)
Enumeration
#MainWindow
EndEnumeration
;Gadget enumeration.
Enumeration
#RichEdit
EndEnumeration
;Font enumeration
Enumeration
#FontEdit
EndEnumeration
#COLOR_Text = $000000 : #EFFECTS_Text = 0
#COLOR_Symbol = $ff00 : #EFFECTS_Symbol = #CFE_italic
#NbBasicKeywords = 64
If OpenWindow(#MainWindow,0,0,400,400,#PB_Window_Invisible | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget,"")
ShowWindow_(WindowID(#MainWindow), #SW_maximize)
If CreateGadgetList(WindowID(#MainWindow))
If LoadFont(#FontEdit, "Courier New", 10)
EditorGadget(#RichEdit,0,50,3*WindowWidth()/4,WindowHeight()-50)
SetGadgetFont(#RichEdit, UseFont(#FontEdit))
SendMessage_(GadgetID(#RichEdit), #EM_SETBKGNDCOLOR, 0, $b6fcf8); Set background colour
Else
MessageRequester("Fatal error","Can't open the 'Courier New' font")
EndIf
EndIf
SendMessage_(GadgetID(#RichEdit), #EM_SETEVENTMASK, 0, #ENM_CHANGE)
ActivateGadget(#RichEdit)
SetWindowCallback(@WindowCallback())
InitSyntaxHighlightning()
;Main message loop..
Repeat
EventID=WaitWindowEvent()
Until EventID=#PB_EventCloseWindow
EndIf
Procedure InitSyntaxHighlightning()
; Build the ValidCharacter table to have have a faster routine to detect
; if the char is a considered as a string or not. Nice improvement :)
For k='0' To '9' ; Tell than the ASCII from 0 to 9 are valid
ValidCharacters(k) = 1
Next
For k='A' To 'Z' ; Tell than the ASCII from A to Z are valid
ValidCharacters(k) = 1
Next
For k='a' To 'z' ; Tell than the ASCII from a to z are valid
ValidCharacters(k) = 1
Next
ValidCharacters('_') = 1
DataSection
BasicKeywords:
Data.s "And", "and"
Data.s "CallDebugger" , "calldebugger"
Data.s "Case" , "case"
Data.s "CompilerCase" , "compilercase"
Data.s "CompilerDefault" , "compilerdefault"
Data.s "CompilerElse" , "compilerelse"
Data.s "CompilerEndIf" , "compilerendif"
Data.s "CompilerEndSelect", "compilerendselect"
Data.s "CompilerIf" , "compilerif"
Data.s "CompilerSelect" , "compilerselect"
Data.s "Data" , "data"
Data.s "DataSection" , "datasection"
Data.s "Debug" , "debug"
Data.s "DebugLevel" , "debuglevel"
Data.s "Declare" , "declare"
Data.s "DeclareDLL" , "declaredll"
Data.s "Default" , "default"
Data.s "DefType" , "deftype"
Data.s "Dim" , "dim"
Data.s "DisableDebugger", "disabledebugger"
Data.s "Else" , "else"
Data.s "ElseIf" , "elseif"
Data.s "EnableDebugger", "enabledebugger"
Data.s "End" , "end"
Data.s "EndDataSection", "enddatasection"
Data.s "EndIf" , "endif"
Data.s "EndProcedure", "endprocedure"
Data.s "EndSelect" , "endselect"
Data.s "EndStructure", "endstructure"
Data.s "EndStructureUnion", "endstructureunion"
Data.s "FakeEndSelect", "fakeendselect"
Data.s "FakeReturn" , "fakereturn"
Data.s "For" , "for"
Data.s "ForEver" , "forever"
Data.s "Global", "global"
Data.s "Gosub", "gosub"
Data.s "Goto" , "goto"
Data.s "If", "if"
Data.s "IncludeBinary", "includebinary"
Data.s "IncludeFile", "includefile"
Data.s "IncludePath", "includepath"
Data.s "NewList", "newlist"
Data.s "Next", "next"
Data.s "Or", "or"
Data.s "Procedure" , "procedure"
Data.s "ProcedureDLL" , "proceduredll"
Data.s "ProcedureReturn", "procedurereturn"
Data.s "Protected" , "protected"
Data.s "Read", "read"
Data.s "Repeat", "repeat"
Data.s "Restore", "restore"
Data.s "Return", "return"
Data.s "Select", "select"
Data.s "Shared", "shared"
Data.s "Step", "step"
Data.s "Structure", "structure"
Data.s "StructureUnion", "structureunion"
Data.s "To", "to"
Data.s "Until", "until"
Data.s "Wend" , "wend"
Data.s "While", "while"
Data.s "XIncludeFile" , "xincludefile"
Data.s "XOr" , "xor"
EndDataSection
EndProcedure
;The following procedure scans the given line of text in the richedit control looking
;For occurrences of the word "test". Such words are coloured And set To italic.
Procedure HighlightLine(Line)
Protected LineText.s, Format.CHARFORMAT, StartPos, Endpos, Left, Right, Flag.b
LineText = LCase(GetGadgetItemText(#RichEdit, Line,0))
;Get the character index's of both ends of the line.
StartPos = sendmessage_(GadgetID(#RichEdit),#EM_LINEINDEX, Line,0)
EndPos = StartPos + Len(LineText)
Format\cbSize = SizeOf(CHARFORMAT)
Format\dwMask = #CFM_COLOR | #CFM_BOLD | #CFM_ITALIC
Left = StartPos
Restore BasicKeywords
Repeat
;Identify possible occurrences of "test"
For a=0 To #NbBasicKeywords
Read inst$
Right = FindString(LineText, inst$, Left-StartPos+1) + StartPos
If Right = StartPos;No occurrences found so colour entire line with the default text colour
SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, EndPos)
Format\crTextColor = #COLOR_Text : Format\dwEffects = #EFFECTS_Text
SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
Left = EndPos
Goto ttt
Else
SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Right-1)
Format\crTextColor = #COLOR_Text : Format\dwEffects = #EFFECTS_Text
SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
Left = Right-1 : Right + 3
SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, Left, Right);Highlight the word "test"
Left = Right
Format\crTextColor = #COLOR_Symbol : Format\dwEffects = #EFFECTS_Symbol
SendMessage_(GadgetID(#RichEdit), #EM_SETCHARFORMAT, #SCF_SELECTION, @Format)
Goto ttt
EndIf
ttt:
Next a
Until Left = EndPos
EndProcedure
;The following call back procedure is responsible for syntax highlighting etc.
;It does this by intercepting the #EN_CHANGE command message which fires whenever
;text in the rich edit control has changed. We then examine the entire line containing the text.
Procedure WindowCallback(hWnd, uMsg, wParam, lParam)
Protected ReturnValue, Chr.CHARRANGE, Line, CurrentStartPos
ReturnValue = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_COMMAND
If wParam >>16 = #EN_CHANGE And lparam = GadgetID(#RichEdit)
;The following returns the index (0-based) of the line containing the current character.
Sendmessage_(GadgetID(#RichEdit),#EM_GETSEL,@CurrentStartPos, @Line)
Line = sendmessage_(GadgetID(#RichEdit),#EM_LINEFROMCHAR, CurrentStartPos,0)
SendMessage_(GadgetID(#RichEdit), #EM_HIDESELECTION, 1,0)
HighlightLine(Line)
If GetAsyncKeyState_(#VK_return) & 1 = 1;Â Bit 0 is set if the enter key was pressed since the last check.
;Investigate the previous line.
HighlightLine(Line-1)
EndIf
SendMessage_(GadgetID(#RichEdit), #EM_SETSEL, CurrentStartPos,CurrentStartPos); Return cursor to its correct position.
SendMessage_(GadgetID(#RichEdit),#EM_SETMODIFY,0,0)
SendMessage_(GadgetID(#RichEdit), #EM_HIDESELECTION, 0,0)
EndIf
EndSelect
ProcedureReturn(Returnvalue)
EndProcedure
Thanks kale!! it's good to see people welcoming you when you're new on the forums!