Date: 02-16-2022
Return to Index
created by gbSnippets
'Back in the day, computer printouts were on paper whose background
'alternated white/green colors every few lines. It made it much easier
'for our eyes to follow the code or to count the number of lines.
'This snippet describes a slightly different way of highlighting
'alternating lines, by using underlines instead of background colors
'as was done in the other to Greenbar snippets.
'Primary Code:
'This version uses an underline margin symbol to underline alternating
'groups of line.
'Here is the code to assign a marker symbol as underline. Two markers are
'used in the snippet below - each with different colors.
SendMessage hSci, %SCI_MarkerDefine, 10,%SC_MARK_Underline
SendMessage hSci, %SCI_MarkerSetBack, 10, Rgb(200,200,200) 'more gray background
'Then this code enables the use of the symbol
SendMessage hSci, %SCI_SetMarginMaskN, i,-1 'all symbols allowed
'And finally, this code adds the marker to alternating lines
Select Case i Mod 6
Case 0,1,2
SendMessage hSci, %SCI_MarkerAdd, i, 10 'line, marker#
Case 3,4,5
SendMessage hSci, %SCI_MarkerAdd, i, 11 'line, marker#
End Select
'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,400,350, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %ID_BtnA, "PushA", 10,10,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
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 : CreateGreenBars
' Case %ID_Sci : If CB.Ctlmsg = %SCEN_Change Then CreateGreenBars
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
Local txt As String, i As Long
For i = 0 To 21
txt = txt + "12345" + $CrLf
Next i
txt = txt + Chr$(0)
SendMessage hSci, %SCI_SetText, 0, StrPTR(txt)
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20
'create 2 background markers, each with a different background color
SendMessage hSci, %SCI_MarkerDefine, 10,%SC_MARK_Underline
SendMessage hSci, %SCI_MarkerSetBack, 10, Rgb(200,200,200) 'more gray background
SendMessage hSci, %SCI_MarkerDefine, 11,%SC_MARK_Underline
SendMessage hSci, %SCI_MarkerSetBack, 11, Rgb(245,245,245) 'less gray background
End Sub
Sub CreateGreenBars
Local i, iLines, iFirstChar, iLastChar As Long
iLines = SendMessage(hSci, %SCI_GetLineCount, 0, 0)
'assign different marker to each group of 3 lines
SendMessage hSci, %SCI_MarkerDeleteAll, -1, 0 'first, remove all markers
For i = 0 To iLines - 1
SendMessage hSci, %SCI_SetMarginMaskN, i,-1 'all symbols allowed
Select Case i Mod 6
Case 0,1,2
SendMessage hSci, %SCI_MarkerAdd, i, 10 'line, marker#
Case 3,4,5
SendMessage hSci, %SCI_MarkerAdd, i, 11 'line, marker#
End Select
Next i
End Sub
'gbs_00642
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm