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.
'Primary Code:
'If the last character on a line has the SCI_StyleSetEOLFilled attribute
'set, the remaniner of the line to the right edge of the window (called
'virtual space) is filled with the background color of the style to which
'the last character is set.
'Here the code to set the attribute:
SendMessage hSci, %SCI_StyleSetEOLFilled, %Style_Gray, 1 '1=on 0=off
'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
%Style_Gray = 1
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
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
SendMessage hSci, %SCI_StyleSetFore, %Style_Gray, Rgb(255,0,0)
SendMessage hSci, %SCI_StyleSetBack, %Style_Gray, Rgb(230,230,230)
SendMessage hSci, %SCI_StyleSetEOLFilled, %Style_Gray, 1
SendMessage hSci, %SCI_StyleSetEOLFilled, %Style_Default, 1
End Sub
Sub CreateGreenBars
Local i, iLines, iFirstChar, iLastChar As Long
iLines = SendMessage(hSci, %SCI_GetLineCount, 0, 0)
For i = 0 to iLines - 1
iFirstChar = SendMessage(hSci, %SCI_PositionFromLine, i, 0)
iLastChar = SendMessage(hSci, %SCI_GetLineEndPosition, i, 0)
Select Case i Mod 6
Case 0,1,2
SendMessage(hSci, %SCI_StartStyling, iFirstChar, 31)
SendMessage(hSci, %SCI_SetStyling, iLastChar-iFirstChar+2, %Style_Gray)
Case 3,4,5
SendMessage(hSci, %SCI_StartStyling, iFirstChar, 31)
SendMessage(hSci, %SCI_SetStyling, iLastChar-iFirstChar+2, %Style_Default)
End Select
Next i
End Sub
'gbs_00640
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm