Date: 02-16-2022
Return to Index
created by gbSnippets
'Styles determine which FG/BG color is used to display text. There are
'39 predefined styles, numbered 0-39. The first 32 styles (0-31)are used to
'set text attributes. The last 7 are pre-defined for various uses, such as
'for styline linenumbers, braces, and other special features of Scintilla.
'When a Scintilla component is created all 39 styles are set to black/white
'FG/BG except style 33, which is set to black on gray for displaying line
'numbers.
'With lexing turned off, text that is typed in uses style 0, regardless
'of the style of text on either side of the caret where typing occurs.
'With lexing turned on, text that is typed in uses a style that is controlled
'by the lexer.
'If the properties of a style are changed, any text that was previously
'displayed with that style will take on the new properties of that style.
'This includes all of the style properties (FG, BG, fontname, size, ...).
'If multiple text colors have been displayed, with varying background colors,
'to set a common background for all characters you must change the background
'for all styles. You can change the background of all styles at one time
'with SCI_StyleClearAll, but this also changes the text color.
'Primary Code:
'These lines can be used with any of the 39 available styles
SendMessage hSci, %SCI_StyleSetFore, %Style_Default, %Blue
SendMessage hSci, %SCI_StyleSetBack, %Style_Default, %Yellow
SendMessage hSci, %SCI_StyleClearAll, 0, 0
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "scintilla_gb.inc"
%ID_Sci = 1000 : %ID_BtnA = 1001 : %ID_BtnB = 1002
Global hDlg, hSci, hLib As DWord
Function PBMain() As Long
hLib = LoadLibrary("SCILEXER.DLL")
Dialog New Pixels, 0, "Scintilla Example",300,300,300,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %ID_BtnA, "PushA", 10,10,70,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnB, "PushB", 10,40,70,20, %WS_Child Or %WS_Visible
Control Add "Scintilla", hDlg, %ID_Sci, "", 100,10,180,130, %WS_Child Or %WS_Visible
Control Handle hDlg, %ID_Sci To hSci 'get handle to Scintilla window
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local txt As String
txt = "Select Case var$ 'first line" + $CrLf + "End Select 'last line" + Chr$(0)
Select Case CB.Msg
Case %WM_InitDialog
InitializeScintilla
PostMessage hSci, %SCI_SetSel, 0,0 'unselect initially
Case %WM_Command
Select Case CB.Ctl
Case %ID_BtnA : TestA
Case %ID_BtnB : TestB
End Select
Case %WM_Size
Control Set Size hDlg, %ID_Sci, Lo(Word, CB.lParam)-110, Hi(Word, CB.lParam)-20
Case %WM_Destroy
If hLib Then FreeLibrary hLib 'free the Scintilla library
End Select
End Function
Sub InitializeScintilla
'Set default FG/BG
SendMessage hSci, %SCI_SetLexer, %SCLEX_Null, 0
SendMessage hSci, %SCI_StyleSetFore, %Style_Default, %Blue
SendMessage hSci, %SCI_StyleSetBack, %Style_Default, %Yellow
SendMessage hSci, %SCI_StyleClearAll, 0, 0 'set all styles to %style_default
End Sub
Sub TestA
Local txt As String
txt = "If x = 2 Then" + $CrLf + " 'do nothing" + $Crlf
txt = txt + "Else" + $crlf + " x = 0" + $crlf + "End If" + Chr$(0)
SendMessage hSci, %SCI_SetText, 0, StrPTR(txt)
End Sub
Sub TestB
SendMessage hSci, %SCI_StyleSetFore, 2, %Red 'style #2 FG set to red
SendMessage hSci, %SCI_StyleSetBack, 2, %Green 'style #2 BB set to green
SendMessage hSci, %SCI_StartStyling, 5, 31 'begin styling at pos=5
SendMessage hSci, %SCI_SetStyling, 10,2 'style next 10 chars with style #2
End Sub
'gbs_00636
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm