Date: 02-16-2022
Return to Index
created by gbSnippets
'Programmers often need to perform in code, keyboard actions which a user might
'do. The following messages are used to emulate keyboard actions. These are
'fairly self-explanatory.
'SCI_LINEDOWN SCI_LINEDOWNEXTEND SCI_LINEDOWNRECTEXTEND SCI_LINESCROLLDOWN
'SCI_LINEUP SCI_LINEUPEXTEND SCI_LINEUPRECTEXTEND SCI_LINESCROLLUP
'SCI_PARADOWN SCI_PARADOWNEXTEND SCI_PARAUP SCI_PARAUPEXTEND
'SCI_CHARLEFT SCI_CHARLEFTEXTEND SCI_CHARLEFTRECTEXTEND
'SCI_CHARRIGHT SCI_CHARRIGHTEXTEND SCI_CHARRIGHTRECTEXTEND
'SCI_WORDLEFT SCI_WORDLEFTEXTEND SCI_WORDRIGHT SCI_WORDRIGHTEXTEND
'SCI_WORDLEFTEND SCI_WORDLEFTENDEXTEND SCI_WORDRIGHTEND SCI_WORDRIGHTENDEXTEND
'SCI_WORDPARTLEFT SCI_WORDPARTLEFTEXTEND SCI_WORDPARTRIGHT SCI_WORDPARTRIGHTEXTEND
'SCI_HOME SCI_HOMEEXTEND [SCI_HOMERECTEXTEND]
'SCI_HOMEDISPLAY SCI_HOMEDISPLAYEXTEND SCI_HOMEWRAP SCI_HOMEWRAPEXTEND
'SCI_VCHOME SCI_VCHOMEEXTEND SCI_VCHOMERECTEXTEND
'SCI_VCHOMEWRAP SCI_VCHOMEWRAPEXTEND
'SCI_LINEEND SCI_LINEENDEXTEND SCI_LINEENDRECTEXTEND
'SCI_LINEENDDISPLAY SCI_LINEENDDISPLAYEXTEND SCI_LINEENDWRAP SCI_LINEENDWRAPEXTEND
'SCI_DOCUMENTSTART SCI_DOCUMENTSTARTEXTEND SCI_DOCUMENTEND SCI_DOCUMENTENDEXTEND
'SCI_PAGEUP SCI_PAGEUPEXTEND SCI_PAGEUPRECTEXTEND
'SCI_PAGEDOWN SCI_PAGEDOWNEXTEND SCI_PAGEDOWNRECTEXTEND
'SCI_STUTTEREDPAGEUP SCI_STUTTEREDPAGEUPEXTEND
'SCI_STUTTEREDPAGEDOWN SCI_STUTTEREDPAGEDOWNEXTEND
'SCI_DELETEBACK SCI_DELETEBACKNOTLINE
'SCI_DELWORDLEFT SCI_DELWORDRIGHT SCI_DELWORDRIGHTEND
'SCI_DELLINELEFT SCI_DELLINERIGHT SCI_LINEDELETE
'SCI_LINECUT SCI_LINECOPY SCI_LINETRANSPOSE SCI_LINEDUPLICATE
'SCI_LOWERCASE SCI_UPPERCASE SCI_CANCEL SCI_EDITTOGGLEOVERTYPE
'SCI_NEWLINE SCI_FORMFEED SCI_TAB SCI_BACKTAB
'SCI_SELECTIONDUPLICATE
'Primary Code:
'This example places a TAB in the context
SendMessage hSci, %SCI_TAB, 0,0
'And this example moves the caret to the end of the document
SendMessage hSci, %SCI_DocumentEnd, 0,0
'Compilable Example: (Jose Includes)
'This code inserts a TAB key at the caret, or moves the caret to the
'end of the document.
#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, "Add TAB", 10,10,70,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnB, "Go To End", 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
SendMessage hSci, %SCI_TAB, 0,0
End Sub
Sub TestB
SendMessage hSci, %SCI_DocumentEnd, 0,0
Control Set Focus hDlg, %ID_Sci
End Sub
'gbs_00648
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm