JackBurman
May 27, 2011
- "Simple Search initial submission"
This is a basic search program that adds a search bar to the top of the HTML HELP window. Enter your search term, hit Find button, and select from results in the dropdown combobox list. The HTML contents window is always available. All selections are viewed in the included browser. There is no link to your default browser. There is no Index window.
This is a bare-bones approach.
[[code format="lb"]]
' LB HTML Simple Search
' Author: jaba (JackBurman)
' Date: May 27, 2011a
'
' History:
' v1.0 May 27, 2011 Submitted Simple Search
'
' This code is free for personal use.
' To protect the rights of others whose code is included, please note following:
' You may not republish this code in its current form.
' You may modify this code for your personal use.
' You may publish a modified version of this code under these conditions:
' 1. You have made major changes to the code.
' 2. You give credit to the original authors
'
' Based on a framework provided by Alyce on LB forum.
'
' Some parts taken from entries by others, including
' Alyce, Janet, Stefan, and Gordon.
'
' Thanks to them and others.
'*** BEGIN PROGRAM ***
InstallDir$ = GetFolder$(GetModuleFileName$())
HelpDir$ = InstallDir$ + "lb4help\LibertyBASIC_4_web\HTML\"
HelpFileIndex$ = InstallDir$; "lb4help\"
ContentsFileName$ = "LibertyBASIC_4.html"
WdoTitle$ = "LB HTML SIMPLE SEARCH"
global wContainer, hContainer
Open "atl" For DLL As #atl
CallDLL #atl, "AtlAxWinInit", Ret As long
nomainwin
[setupGUIWdo]
WindowWidth = 800
WindowHeight = DisplayHeight-60'735
UpperLeftX = DisplayWidth - WindowWidth
UpperLeftY = 2
statictext #s.st1, "Search for:", 10, 5, 100, 18
stylebits #s.default, _BS_DEFPUSHBUTTON, 0, 0, 0
button #s.default "Find", [findPages], UL, 265, 21, 80, 25
button #s.toc "Table of Contents", [tocButton], UL, 350, 21, 115, 25
combobox #s.pages, found$(), [displaySelectedPage], 10, 23, 250, 150
'hidden index window
listbox #s.index, index$(), [pickBox], 1610, 185, 172, 320
graphicbox #s.resource 0, 50, 784, 625 'container for browser control
wContainer = 780
hContainer = 625
[openGUIWdo]
open WdoTitle$ for window as #s
#s "trapclose [quit]"
#s.st1 "!font sans_serif 9 bold"
#s "resizehandler [resized]"
'display table of contents in browse control
QuickViewPage$ = "libe3mnn.htm"
call createBrowseControl HelpFileIndex$, ContentsFileName$, hFlag
dim info$(10,10)
files HelpDir$, "*.htm", info$()
numFiles = val(info$(0,0))
'load index array
dim index$(numFiles)
scan
for i = 1 to numFiles
open HelpDir$ + info$(i,0) for input as #file
txt$ = INPUT$(#file, lof(#file))
index$(i) = GetTitle$(txt$); chr$(0); info$(i,0)
close #file
next i
sort index$(), 1, numFiles
#s.index "reload"
#s.pages "setfocus"
wait
[resized]
wWid = WindowWidth
wHig = WindowHeight
#s.resource "locate 0 50 "; wWid-16;" "; wHig-80
wContainer = wWid - 20
hContainer = wHig-80
calldll #user32, "MoveWindow",_
hFlag As ulong,_
0 As long,_
0 As long,_
wContainer As long,_
hContainer As long,_
1 As long,_
result As void
#s "refresh"
wait
[tocButton]
QuickViewPage$ = "libe3mnn.htm"
call createBrowseControl HelpFileIndex$, ContentsFileName$, hFlag
wait
[findPages]
#s.pages "contents? term$"
if term$ = "" then
redim found$(1)
#s.pages "reload"
wait
end if
dim found$(numFiles)
for i = 1 to numFiles
open HelpDir$ + info$(i,0) for input as #file
txt$ = INPUT$(#file, lof(#file))
if instr(txt$, term$) >0 then
found$(i) = GetTitle$(txt$); chr$(0); info$(i,0)
#s.pages "reload"
end if
close #file
next
#s.pages "selectionindex? index" 'set index to 0. Seems to be necessary
'to enable selecting first item in
'combobox list to display in browser.
wait
[displaySelectedPage]
#s.pages "selection? FileName$"
FileName$ = word$(FileName$, 2, chr$(0))
call createBrowseControl HelpDir$, FileName$, hFlag
wait
[pickbox]
wait
[quit]
close #s
close #atl
end
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXSUBS AND FUNCTIONS
'credit: Alyce's entry.
'extract title from html text
function GetTitle$(s$)
marker1=instr(upper$(s$), "<A NAME=")
marker1=instr(upper$(s$), "<B>",marker1)+3
marker2=instr(upper$(s$), "</B>", marker1)
lenTitle=marker2-marker1
GetTitle$=mid$(s$,marker1,lenTitle)
end function
'borrowed from Stefan Pendl
function GetModuleFileName$()
nSize = _MAX_PATH + 1
lpFilename$ = space$(nSize); CHR$(0)
calldll #kernel32, "GetModuleFileNameA",_
hModule as uLong,_
lpFilename$ as ptr,_
nSize as uLong,_
result as uLong
if result > 0 then GetModuleFileName$ = trim$(lpFilename$)
end function
function GetFolder$(Path$)
pos = 1
GetFolder$ = Path$
while pos > 0
pos = instr(Path$, "\", pos)
if pos > 0 then
GetFolder$ = left$(Path$, pos)
pos = pos + 1
end if
wend
end function
sub createBrowseControl D$, F$, byref hATL
if hATL then
CallDLL #user32, "DestroyWindow", _
hATL As ulong, _
result As long
hATL = 0
end if
hWndContainer = hWnd(#s.resource) 'graphicbox handle
callDLL #user32, "GetWindowLongA", _
hWndContainer as ulong, _
_GWL_HINSTANCE as long, _
hInst as ulong
ResName$ = D$ + F$ 'file to display
cw = wContainer-3
ch = hContainer
style = _WS_CHILD or _WS_VISIBLE or _WS_VSCROLL
CallDLL #user32, "CreateWindowExA", _
_WS_EX_STATICEDGE As long, _ 'extended type
"AtlAxWin" As ptr, _ 'class name
ResName$ As ptr, _ 'resource file name & path
style As long, _ 'window style
1 As long, _ 'left x pos
1 As long, _ 'top y pos
cw As long, _ 'width
ch As long, _ 'height
hWndContainer As ulong, _ 'handle of container
100 As long, _ 'handle to menu or child window ID
hInst As ulong, _ 'parent instance handle
0 As long, _ 'window creation data
hATL As ulong 'handle of active template library control
end sub
function fileExists(path$, filename$)
files path$, filename$, info$()
fileExists = val(info$(0, 0))
end function
[[code]]