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 longer template, which includes two buttons that are
'used to enable/disable various Scintilla features.
'The other, shorter template does not include the two buttons.
'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 'set margin 0 width=20
Control Set Focus hDlg, %ID_Sci 'focus
End Sub
'The buttons use standard PowerBASIC statements, with each button click calling
'a separate test procedure.
Case %WM_Command
Select Case CB.Ctl
Case %ID_BtnA : TestA
Case %ID_BtnB : TestB
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,300,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %ID_BtnA, "PushA", 10,10,70,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnB, "PushB", 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
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"
txt = txt + $crlf + " 'do nothing"
txt = txt + $crlf + "Else"
txt = txt + $crlf + " x = 0"
txt = txt + $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
MsgBox "template placeholder for demo code"
End Sub
Sub TestB
MsgBox "template placeholder for demo code"
End Sub
'gbs_00629
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm