Date: 02-16-2022
Return to Index
created by gbSnippets
'This example uses the CPRINT console function to display messages in an
'app containing the Scintilla control.
'Primary Code:
'This code is typically called from within a Callback function to list
'the various message the callback function receives.
'Credit: Semen Matusovski
Sub CPrint (SOut As String)
Static hConsole As Long, cWritten As Long
If hConsole = 0 Then AllocConsole: hConsole = GetStdHandle(-11&)
WriteConsole hConsole, ByCopy sOut + $CrLf, Len(sOut) + 2, cWritten, ByVal 0&
End Sub
'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
Declare Function WinMsg LIB "WINMSG.DLL" ALIAS "WindowMessageA" (ByVal MsgNum As Long) AS String
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
Static iMsgCount As Long
CPrint Str$(iMsgCount&)+ " " + WinMsg(CB.Msg) 'Console message code
Incr iMsgCount&
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
Sub CPrint (SOut As String)
Static hConsole As Long, cWritten As Long
If hConsole = 0 Then AllocConsole: hConsole = GetStdHandle(-11&)
WriteConsole hConsole, ByCopy sOut + $CrLf, Len(sOut) + 2, cWritten, ByVal 0&
End Sub
'gbs_00606
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm