Date: 02-16-2022
Return to Index
created by gbSnippets
'A program interfaces with Scintilla through the use of messages, in the
'same way as it would with other controls such as the RichEdit control.
'The difference is that all of the messages have been defined by the author
'of Scintilla - the messages are not standard Windows messages.
'For example, with a RichEdit control, a program might send this message:
iLines = SendMessage(hRichEdit, %EM_GetLineCount, 0,0)
'To control Scintilla, a program would send a message this way:
iLines = SendMessage(hSci, %SCI_GetLineCount, 0, 0)
'Both messages are sent using the Windows SendMessage function. But they
'are different in that Scintilla has defined it's own series of message
'equates, which are not the same as standard Windows equates.
'The two examples above are almost identical, using _GetLineCout in the
'equate name. But many Scintilla message equates have no matching standard
'Windows equates, such as these two Scintilla messages:
SendMessage hSci, %Sci,AutoCStops, 0, StrPTR(txt)
SendMessage hSci, %SCi_CallTipShow, iPos, StrPTR(txt)
'Scintilla supports almost 500 messages. About 10% deal with getting/setting
'text, whereas the majority set or get various attributes or information about
'content of the control.
'Primary Code:
'To set the text in a Scintilla control, use this code
txt = "Line One" + $Nul
SendMessage hSci, %SCi_SetText, 0, StrPTR(txt)
'Most Scintilla messages which send/receive text require that the text
'be zero-terminated, i.e., end with &nul, which is the same as Chr$(0).
'To get the number of lines of code in the control, use this message
iLines = SendMessage(hSci, %SCi_GetLineCount,0,0)
'Compilable Example: (Jose Includes)
'This example uses the minimal code from the previous snippet an demonstrates
'just two messages - one that sends text to Scintilla and another that receives
'a numerical value from Scintilla.
#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, "Test Code",300,300,300,400, %WS_OverlappedWindow To hDlg
Control Add "Scintilla", hDlg, %ID_Sci, "", 10,10,280,380, %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 iLines As Long
Local txt As String
Select Case CB.Msg
Case %WM_InitDialog
txt = "Line One" + $Nul
SendMessage hSci, %SCi_SetText, 0, StrPTR(txt)
iLines = SendMessage(hSci, %SCi_GetLineCount,0,0)
MsgBox Str$(iLines) + " line(s)"
End Select
End Function
'gbs_00679
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm