Date: 02-16-2022
Return to Index
created by gbSnippets
'Scintilla provides zoom support - allowing you to increase/decrease the font
'size of the entire control by 1 point at a time or by a specified number of points.
'If you set the zoom level to 0, no zoom is in effect.
'Primary Code:
'Here are various messages which set zoom values:
SendMessage hSci, %SCI_ZoomIn, 0, 0 'make larger, 1 point per click
SendMessage hSci, %SCI_ZoomOut, 0, 0 'make smaller, 1 point per click
SendMessage hSci, %SCI_SetZoom, 20, 0 'set to +20 point zoom
SendMessage hSci, %SCI_SetZoom, 0, 0 'remove zoom (zoom=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
%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, "Zoom In", 10,10,70,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnB, "Zoom Out", 10,40,70,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnC, "Zoom +20" , 10,70,70,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnD, "Reset", 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
Case %WM_Command
Select Case CB.Ctl
Case %ID_BtnA : TestA
Case %ID_BtnB : TestB
Case %ID_BtnC : TestC
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 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
Control Set Focus hDlg, %ID_Sci 'focus
End Sub
Sub TestA
SendMessage hSci, %SCI_ZoomIn, 0, 0 'make larger, 1 point per click
End Sub
Sub TestB
SendMessage hSci, %SCI_ZoomOut, 0, 0 'make smaller, 1 point per click
End Sub
Sub TestC
SendMessage hSci, %SCI_SetZoom, 20, 0 'set zoom to +20 points
End Sub
Sub TestD
SendMessage hSci, %SCI_SetZoom, 0, 0 'remove zoom (zoom=0)
End Sub
'gbs_00632
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm