Date: 02-16-2022
Return to Index
created by gbSnippets
'Several features of the caret, which visually denotes the current position
'within the Scintilla control, can be controlled.
' - graphic type (line vs block)
' - width
' - color (FG and BG)
' - blinking speed
' - visibility
' - alpha transparency.
'This snippet demonstrates how to change the type, width and color of the caret.
'Primary Code:
'These mesages control the width, FG color and style of the caret:
SendMessage hSci, %SCI_SetCaretWidth, 3, 0 'width = 3 pixels
SendMessage hSci, %SCI_SetCaretFore, %Red, 0 'color = %Red
SendMessage hSci, %SCI_SetCaretStyle, 2, 0 '0=not visible 1=line 2=block
'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, "Modified Caret 1", 10,10,90,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnB, "Modified Caret 2", 10,40,90,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
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)
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20
Control Set Focus hDlg, %ID_Sci 'focus
End Sub
Sub TestA
SendMessage hSci, %SCI_SetCaretWidth, 3, 0 'width = 3 pixels
SendMessage hSci, %SCI_SetCaretFore, %Red, 0 'color = %Red
SendMessage hSci, %SCI_SetCaretStyle, 2, 0 '0=not visible 1=line 2=block
Control Set Focus hDlg, %ID_Sci 'focus
End Sub
Sub TestB
SendMessage hSci, %SCI_SetCaretWidth, 1, 0 'width = 3 pixels
SendMessage hSci, %SCI_SetCaretFore, %Green, 0 'color = %Green
SendMessage hSci, %SCI_SetCaretStyle, 1, 0 '0=not visible 1=line 2=block
Control Set Focus hDlg, %ID_Sci 'focus
End Sub
'gbs_00630
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm