Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Debug Error On 'catch array/pointer errors - OFF in production
#Debug Display On 'display untrapped errors - OFF in production
#Include "Win32API.inc"
#Include "scintilla_gb.inc"
%ID_Sci = 1000
Global hDlg, hSci, hLib As DWord
Global WordList As String
Global ListSeparator As Long
Function PBMain() As Long
hLib = LoadLibrary("SCILEXER.DLL")
Dialog New Pixels, 0, "Scintilla Example",300,300,300,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 iPos, iLine, iReturn As Long, CharAtLeft As String
Local pNSC As SCNotification Ptr ' // Scintilla notification messages
Select Case CB.Msg
Case %WM_InitDialog
InitializeScintilla
PostMessage hSci, %SCI_SetSel, 0,0 'unselect initially
Case %WM_Notify
Select Case CB.NmID
Case %ID_SCi
pNSC = CB.lParam
CharAtLeft = Chr$(@pNSC.ch)
iPos = SendMessage( hSci, %SCI_GetCurrentPos, 0, 0) 'get current position
Select Case @pNSC.hdr.Code
Case %SCN_CHARADDED
Dialog Set Text hDlg, str$(@pNSC.ch)
If @pNSC.ch = 10 Then
iLine = SendMessage( hSci, %SCI_LineFromPosition, iPos, 0) 'new line #
iReturn = SendMessage( hSci, %SCI_GetLineIndentation, iLine-1, 0) 'indentation, previous line
SendMessage( hSci, %SCI_SetLineIndentation, iLine, iReturn)
End If
End Select
End Select
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
SendMessage hSci, %SCI_GoToPos, 2, 0 'no selection (set anchor=curpos=iPos)
Control Set Focus hDlg, %ID_Sci
ListSeparator = Asc(":") 'not use space because PowerBASIC uses 3-word keyword groups
SendMessage hSci, %SCI_AutoCSetSeparator, ListSeparator, 0 'set separator
WordList = "End Class :End Function :End If :End Interface :End Macro :End Method "
WordList = WordList + ":End Property :End Sub :End Type :End Union :End Try " + $Nul
'set indent size to 4 spaces
SendMessage hSci, %SCI_SetIndent, 3, 0 'set indent size to 4 spaces
SendMessage hSci, %SCI_SetTABIndents, 1, 0 'force TAB to indent within white space area
SendMessage hSci, %SCI_SetBackspaceUnindents, 1, 0 'force backspace to unindent within white space area
SendMessage hSci, %SCI_StyleSetFore, %Style_IndentGuide, %Red
SendMessage hSci, %Sci_SetIndentationGuides, %SC_IV_LookBoth, 0
End Sub
'gbs_00003
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm