Date: 02-16-2022
Return to Index
created by gbSnippets
'Cut/copy/paste actions on text can be done by code, just as a user can do with
'keyboard commands or with the built-in Scintilla context menu commands.
'Scintilla also offers a few special copy commands
' - testing to see if content is available to be pasted
' - copy the current line
' - copy a range of text/characters
' - copy a specified text
' - convert line endings, during paste, to current document's line ending style
'Primary Code:
'The cut/copy commands work on the currect selection. If there is no selection
'they have no effect.
SendMessage hSci, %SCI_Cut, 0,0
SendMessage hSci, %SCI_Copy, 0,0
'The paste command
SendMessage hSci, %SCI_Paste, 0,0
'Copy current line (selection must be empty)
SendMessage hSci, %SCI_CopyAllowLine, 0,0
'Copy range of text
SendMessage hSci, %SCI_CopyRange, 0, 25 'copy characters 0 thru 25
'Copy specified text
txt = "copy this!" + Chr$(0)
SendMessage hSci, %SCI_CopyText, 0,0
'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" + $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
End Sub
Sub TestA
Local txtz As Asciiz * 20
txtz = "copy this!"
SendMessage hSci, %SCI_CopyText, Len(txtz), VarPTR(txtz)
End Sub
Sub TestB
SendMessage hSci, %SCI_Paste, 0,0
End Sub
'gbs_00650
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm