Date: 02-16-2022
Return to Index
created by gbSnippets
'Modification State:
'To set current content of the Scintilla control as the unmodified state of the
'document, such as when a document is loaded or saved, use the following message:
SCI_SetSavePoint
'When an undo/redo operation causes the document to enter the save point, the
'container receives one of these two messages:
SCN_SAVEPOINTREACHED
SCN_SAVEPOINTLEFT
'The SCN_SavePointLeft message is not sent for undo/redo operations when the
'document state before and after the operation is not at the save point.
'The container can also simply query Scintilla to find out the modified state
'of the document using this message:
SCI_GETMODIFY
'Scintilla determines if the modified status of a document by the undo position
'relative to the save point.
'Monitoring Content Change:
'There are 4 notifications which related to a change in text or style in the
'content of the control, sent in this order:
SCEN_Change 'text changes (not style)
*SCN_Modified 'text or styling about to be changed
'cannot modify document in this event
*SCN_CharAdded 'when user types text character (char is found in SCNotification.ch)
'sent before character is styled
SCN_UpdateUI 'text or styling has changed
'or selection range has changed
'use in place of SCN_PosChanged (deprecated)
'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 : %ID_BtnC = 1003 : %ID_BtnD = 1004
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, "Undo", 10,10,70,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnB, "Redo", 10,40,70,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnC, "Set Save Point", 10,70,90,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnD, "Set Style", 10,100,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
SendMessage hSci, %SCI_SetSavePoint, 0, 0
Case %WM_Command
Select Case CB.Ctl
Case %ID_BtnA : TestA
Case %ID_BtnB : TestB
Case %ID_BtnC : SendMessage (hSci, %SCI_SetSavePoint, 0, 0)
Case %ID_BtnD : TestD
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 SendMessage(hSci, %SCI_GetModify, 0, 0) Then
? "modified"
End If
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
SendMessage hSci, %SCI_Undo, 0,0
End Sub
Sub TestB
SendMessage hSci, %SCI_Redo, 0,0
End Sub
Sub TestD
SendMessage hSci, %SCI_StyleSetFore, 0, Rgb(255,0,0)
SendMessage hSci, %SCI_StyleSetBack, 0, Rgb(255,255,0)
'
' SendMessage(hSci, %SCI_StartStyling, 0, 31)
' iLen = SendMessage(hSci, %SCI_GetTextLength, 0, 0)
' SendMessage(hSci, %SCI_SetStyling, iLen, %Style_Default)
End Sub
'gbs_00680
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm