Date: 02-16-2022
Return to Index
created by gbSnippets
'This snippet adds a few lines to the previous "Minimal Code" snippet.
'A line number margin is added, the control resizes when the dialog
'is resized, and the Scintilla library is unloaded when the application ends.
'It also shows how communicating with the Scintilla control is done by
'way of messages - using SendMessage to send messages to the control.
'Other snippets go into messaging in much more detail.
'Primary Code:
'Make the line number margin visible
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20 '0=first margin 20=width in pixels
'Resize the Scintilla control when the application is resized
Case %WM_Size
Control Set Size hDlg, %ID_Sci, Lo(Word, CB.lParam)-110, Hi(Word, CB.lParam)-20
'Free the Scintilla libary when the application closes
If hLib Then FreeLibrary hLib 'free the Scintilla library
'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
Global hDlg, hSci, hLib As DWord
Function PBMain() As Long
hLib = LoadLibrary("SCILEXER.DLL")
Dialog New Pixels, 0, "Scintilla Example",300,300,300,200, %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 txt As String
txt = "Hello Scintilla control!" + $CrLf + "Goodbye RichEdit control!" + Chr$(0)
Select Case CB.Msg
Case %WM_InitDialog
SendMessage(hSci, %SCI_SetText, 0, StrPTR(txt)) 'put text into the control
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20 'set margin 0 to width 20 pixels
PostMessage hSci, %SCI_SetSel, 0,0 'no selection to start with
Control Set Focus hDlg, %ID_Sci 'focus
Case %WM_Size
Control Set Size hDlg, %ID_Sci, Lo(Word, CB.lParam)-20, Hi(Word, CB.lParam)-20
Case %WM_Destroy
If hLib Then FreeLibrary hLib 'free the Scintilla library
End Select
End Function
'gbs_00627
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm