Date: 02-16-2022
Return to Index
created by gbSnippets
'All of my Scintilla snippets, which provide examples of the various features
'Scintilla offers, start with one of two templates. This snippet is the shorter
'template, and is used to demonstrate features which are enabled when the program
'is loaded.
'The second template includes two buttons which typically enable/disable various
'Scintilla features when pressed.
'Primary Code:
'When the template starts, the %WM_InitDialog message is used to initialize
'the Scintilla control and to unselect the contents of the control.
Case %WM_InitDialog
InitializeScintilla 'create line number margin, add sample text
PostMessage hSci, %SCI_SetSel, 0,0 'remove selection of sample text
'All of the initialization commands are placed into a single procedure
'called "InitializeScintilla".
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) 'set text
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20 'display line number margin (set width=20)
Control Set Focus hDlg, %ID_Sci 'focus
End Sub
'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
Global hDlg, hSci, hLib As DWord
Function PBMain() As Long
hLib = LoadLibrary("SCILEXER.DLL")
Dialog New Pixels, 0, "Scintilla Example",300,300,200,150, %WS_OverlappedWindow To hDlg
Control Add "Scintilla", hDlg, %ID_Sci, "", 10,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_Size
Control Set Size hDlg, %ID_Sci, Lo(Word, CB.lParam)-20, 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) 'set text
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20 'set line number margin 0 to width=20
Control Set Focus hDlg, %ID_Sci 'focus
End Sub
'gbs_00628
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm