Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile Exe
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "scictrl.inc"
#Include "HTMLHelp.inc"
Enum Equates Singular
IDC_Sci = 500
IDC_Button
End Enum
Global hDlg, hSci, hLib As Dword
Global Keys() As String
Function PBMain() As Long
hLib = LoadLibrary("SCILEXER.DLL")
Dialog New Pixels, 0, "Scintilla Example",300,300,230,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button, "Help", 10,10,50,20, %WS_Child Or %WS_Visible
Control Add "Scintilla", hDlg, %IDC_Sci, "", 10,50,210,140, %WS_Child Or %WS_Visible Or %WS_Border
Control Handle hDlg, %IDC_Sci To hSci 'get handle to Scintilla window
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
BuildKeys
InitializeScintilla
PostMessage hSci, %SCI_SetSel, 0,0 'unselect initially
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
? KeyWordSequence(hSci)
OpenPage KeyWordSequence(hSci), "C:\pbwin10\bin\pbwin.chm"
End Select
Case %WM_Destroy
If hLib Then FreeLibrary hLib 'free the Scintilla library
End Select
End Function
Sub InitializeScintilla
Local temp$
temp$ = "Select Case" + $CrLf
temp$ += " Case 5" + $CrLf
temp$ += " Clipboard Set Text x$" + $CrLf
temp$ += " Case 6" + $CrLf
temp$ += " If x = 2 Then" + $CrLf
temp$ += " Incr x" + $CrLf
temp$ += " End If" + $CrLf
temp$ += "End Select"
Sci_SetText hSci, temp$
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20 'set line number margin 0 to width=20
Control Set Focus hDlg, %IDC_Sci 'focus
End Sub
Function KeyWordSequence(hSci As Dword) As String
Local WA, WB, WC, WD, WE, WF As String, temp$
Local iPos, iLineLength, iCount, iReturn As Long, RightText, LeftText As String
'if nothing selected, BEEP and return no strings
WC = Sci_GetSelText(hSci)
If Len(WC) = 0 Then Beep : Exit Function
'get string on either side of selection
iLineLength = SendMessageA(hSci, %SCI_GetCurLine,0,0)
temp$ = Space$(iLineLength + 1)
iPos = SendMessageA(hSci, %SCI_GetCurLine, 0, StrPtr(temp$))
temp$ = Remove$(temp$, Chr$(0))
LeftText = Trim$(Left$(temp$,iPos - Len(WC)))
RightText = Trim$(Mid$(temp$,iPos+1))
'get right-most 2 words on left side
iCount = ParseCount(LeftText, $Spc)
If iCount > 1 Then WA = Parse$(LeftText,$Spc,iCount-1)
If iCount > 0 Then WB = Parse$(LeftText,$Spc,iCount)
'get left-most 2 words on right side
iCount = ParseCount(RightText, $Spc)
If iCount > 0 Then WD = Parse$(RightText,$Spc,1)
If iCount > 1 Then WE = Parse$(RightText,$Spc,2)
Array Scan Keys(), Collate UCase, = WA, To iReturn : WA = IIf$(iReturn, WA + $Spc, "")
Array Scan Keys(), Collate UCase, = WB, To iReturn : WB = IIf$(iReturn, WB + $Spc, "")
Array Scan Keys(), Collate UCase, = WD, To iReturn : WD = IIf$(iReturn, $Spc + WD, "")
Array Scan Keys(), Collate UCase, = WE, To iReturn : WE = IIf$(iReturn, $Spc + WE, "")
Function = WA + WB + WC + WD + WE
End Function
Function OpenPage(Key As WStringZ * %Max_Path, HelpFile As WStringZ * %Max_Path) As String
Local kw As HH_AKLINK
kw.cbStruct = SizeOf(kw)
kw.pszKeywords = VarPtr(Key)
kw.fIndexOnFail = %True
HtmlHelp(hDlg, HelpFile, %HH_KEYWORD_LOOKUP, VarPtr(kw))
End Function
Sub BuildKeys
ReDim Keys(10)
Keys(0) = "CASE"
Keys(1) = "DIALOG"
Keys(2) = "SET"
Keys(3) = "END"
Keys(4) = "SUB"
Keys(5) = "SELECT"
Keys(6) = "ELSE"
Keys(7) = "TREEVIEW"
Keys(8) = "CLIPBOARD"
Keys(9) = "TEXT"
Keys(10)= "XPRINT"
End Sub
'gbs_01398
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm