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 how to display this "greenbar" effect in a
'Scintilla control - using a different technique than the original
'greenbar snippet
'Primary Code:
'Here is the code to assign a marker symbol as background. Two markers are
'used in the snippet below - each with different colors.
SendMessage hSci, %SCI_MarkerDefine, 10,%SC_MARK_Background
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, "Add", 10,10,70,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnB, "Remove", 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
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(1)
Case %ID_BtnB : CreateGreenBars(0)
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_BACKGROUND
SendMessage hSci, %SCI_MarkerSetBack, 10, Rgb(230,230,230) 'more gray background
SendMessage hSci, %SCI_MarkerDefine, 11,%SC_MARK_BACKGROUND
SendMessage hSci, %SCI_MarkerSetBack, 11, Rgb(250,250,250) 'less gray background
SendMessage hSci, %SCI_MarkerDefine, 12,%SC_MARK_BACKGROUND
SendMessage hSci, %SCI_MarkerSetBack, 12, %White 'white background
End Sub
Sub CreateGreenBars(Flag As Long)
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
If Flag Then
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
Else
SendMessage hSci, %SCI_MarkerAdd, i, 12 'line, marker#
End If
Next i
End Sub
'gbs_00641
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm