guest (67.164.213.226) guest (67.164.213.226) May 9, 2011 - "Added GetModuleFileName$() routine"

Version 1.01 1.02 added with Browser Control GetModuleFileName$() routine
 ' LB Help Search entry 
' Author: jaba
' Date: May 5, 2011
'
' History:
' v1.0 May 6, 2011 Submitted
' v1.01 May 6, 2011 Added browser control
' v1.02 May 9, 2011 Added GetModuleFileName$() routine
'
' This code is free for personal use.
'
' 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.
'
' This is a basic and minimum interface which uses the default browser
' to display search terms. As I learn more, I may include a browser control
' in the interface, which I think is the best and fastest way to display
' the search terms. But, for now, I'm happy to be making a submission.
'
' To display the Reserved Word List, I edited the .htm file and saved it
' as a .txt file in my /HTML/ sub folder. The user will see the html
' file in the lower textbox, which includes html tags. I have not made a
' parser yet, or included the browser control to display html files.
' At this point, it's an idea only.
'

' Thanks to Stefan Pendl for API function method to obtain location of
' LB installation directory. This method is more reliable with systems
' running Vista/Win7 than is the StartupDir$ or DefaultDir$ method.
InstallDir$ = GetFolder$(GetModuleFileName$())
HelpDir$ = StartupDir$ InstallDir$ + "lb4help\LibertyBASIC_4_web\HTML\"
ReservedWordPage$ = HelpDir$ + "libe6ldg.htm"'"libe6ldg.txt"
HelpFileIndex$ = StartupDir$; InstallDir$; "lb4help\LibertyBASIC_4.html"

nomainwin
WindowWidth = 442
WindowHeight = 520
UpperLeftX = DisplayWidth - WindowWidth
UpperLeftY = 40

statictext #s.search "Search for: ", 10, 15, 200, 20
textbox #s.term 10, 35, 320, 25
button #s.default "Find", [getIt], UL, 340, 35, 80, 25
listbox #s.pages, found$(), [ListPages], 10, 65, 410, 200
statictext #s.heading "Commands and Reserved Word List", 10, 270, 300, 20 '' stylebits #s.reserved, _WS_VSCROLL, _ES_AUTOHSCROLL, 0, 0 '' textbox #s.reserved 10, 290, 410, 170
graphicbox #s.reserved 10, 290, 410, 170 'container for browser control
button #s.content "Contents", [startBrowser], UL, 340, 5, 80, 25

open "Search Me!" for dialog_nf as #s
#s "trapclose [quit]"

#s.content "!font ms_sans_serif 9 bold"
#s.search "!font ms_sans_serif 9 bold"
#s.heading "!font ms_sans_serif 9 bold"
'' #s.reserved "!font courier_new 8"
gosub [createBrowseControl] 'branch to load browser control and reserved word list
'' #s.reserved ReservedWordList$(ReservedWordPage$)
#s.term "!setfocus"

dim info$(10,10)
files HelpDir$, "*.htm", info$()

numFiles = val(info$(0,0))
wait

[getIt]
#s.term "!contents? term$"

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
wait

[ListPages]
#s.pages "selection? FileName$"
FileName$ = word$(FileName$, 2, chr$(0))

run "rundll32.exe url.dll,FileProtocolHandler "; chr$(34); HelpDir$; FileName$; chr$(34)

wait

[startBrowser]
run "rundll32.exe url.dll,FileProtocolHandler "; chr$(34); HelpFileIndex$; chr$(34)
#s.term "!setfocus"
wait

[quit] 'How can I close browser window programmatically? ' notice "Be sure to close browser!"
close #s
close #atl
end

'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

''This 'borrowed from Stefan Pendl
'added 5/9/11
function is not needed when using browser control 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 ReservedWordList$(page$) open page$ for input as #file ReservedWordList$ = INPUT$(#file, lof(#file)) close #file

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


''The following routine was copied nearly verbatim from the ATL Tutorial at
'' http://lbpe.wikispaces.com/ATL+Tutorial by Alyce Watson. I used the first
'' three snippets from the demo - ATL DLL, and Creating the control. I
'' refered to the entries by Stefan and Alyce to learn what variables needed
'' to be changed to fit my program. I was surprised at how well it worked for
'' so little investment of my time and energy.
[createBrowseControl]
hWndContainer = hWnd(#s.reserved) 'graphicbox handle

Open "atl" For DLL As #atl

CallDLL #atl, "AtlAxWinInit", Ret As long

callDLL #user32, "GetWindowLongA", _
hWndContainer as ulong, _
_GWL_HINSTANCE as long, _
hInst as ulong

ResName$ = ReservedWordPage$

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, _ 'URL, or progID or CLSID -file name
style As long, _ 'window style
0 As long, _ 'left x pos
0 As long, _ 'top y pos
408 As long, _ 'width
168 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

return

Initial submission Version 1.0 1.01 added with Browser Control
 ' LB Help Search entry 
' Author: jaba
' Date: May 5, 2011
'
' History:
' v1.0 May 6, 2011 Submitted
' v1.01 May 6, 2011 Added browser control
'
' This code is free for personal use.
'
' 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.
'
' This is a basic and minimum interface which uses the default browser
' to display search terms. As I learn more, I may include a browser control
' in the interface, which I think is the best and fastest way to display
' the search terms. But, for now, I'm happy to be making a submission.
'
' To display the Reserved Word List, I edited the .htm file and saved it
' as a .txt file in my /HTML/ sub folder. The user will see the html
' file in the lower textbox, which includes html tags. I have not made a
' parser yet, or included the browser control to display html files.
' At this point, it's an idea only.
'

HelpDir$ = StartupDir$ + "lb4help\LibertyBASIC_4_web\HTML\"
ReservedWordPage$ = HelpDir$ + "libe6ldg.htm"'"libe6ldg.txt"
HelpFileIndex$ = StartupDir$; "lb4help\LibertyBASIC_4.html"


nomainwin
WindowWidth = 442
WindowHeight = 520
UpperLeftX = DisplayWidth - WindowWidth
UpperLeftY = 40

statictext #s.search "Search for: ", 10, 15, 200, 20
textbox #s.term 10, 35, 320, 25
button #s.default "Find", [getIt], UL, 340, 35, 80, 25
listbox #s.pages, found$(), [ListPages], 10, 65, 410, 200
statictext #s.heading "Commands and Reserved Word List", 10, 270, 300, 20
'' stylebits #s.reserved, _WS_VSCROLL, _ES_AUTOHSCROLL, 0, 0
'' textbox #s.reserved 10, 290, 410, 170
graphicbox #s.reserved 10, 290, 410, 170 'container for browser control
button #s.content "Contents", [startBrowser], UL, 340, 5, 80, 25



open "Search Me!" for dialog_nf as #s
#s "trapclose [quit]"

#s.content "!font ms_sans_serif 9 bold"
#s.search "!font ms_sans_serif 9 bold"
#s.heading "!font ms_sans_serif 9 bold"
'' #s.reserved "!font courier_new 8"


gosub [createBrowseControl] 'branch to load browser control and reserved word list

'' #s.reserved ReservedWordList$(ReservedWordPage$)
#s.term "!setfocus"

dim info$(10,10)
files HelpDir$, "*.htm", info$()

numFiles = val(info$(0,0))
wait

[getIt]
#s.term "!contents? term$"

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
wait

[ListPages]
#s.pages "selection? FileName$"
FileName$ = word$(FileName$, 2, chr$(0))

run "rundll32.exe url.dll,FileProtocolHandler "; chr$(34); HelpDir$; FileName$; chr$(34)

wait

[startBrowser]
run "rundll32.exe url.dll,FileProtocolHandler "; chr$(34); HelpFileIndex$; chr$(34)
#s.term "!setfocus"
wait



[quit]
'How can I close browser window programmatically?
' notice "Be sure to close browser!"
close #s
close #atl
end

'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

''This function is not needed when using browser control
function ReservedWordList$(page$)
open page$ for input as #file
ReservedWordList$ = INPUT$(#file, lof(#file))
close #file
end function


''The following routine was copied nearly verbatim from the ATL Tutorial at
'' http://lbpe.wikispaces.com/ATL+Tutorial by Alyce Watson. I used the first
'' three snippets from the demo - ATL DLL, and Creating the control. I
'' refered to the entries by Stefan and Alyce to learn what variables needed
'' to be changed to fit my program. I was surprised at how well it worked for
'' so little investment of my time and energy.
[createBrowseControl]
hWndContainer = hWnd(#s.reserved) 'graphicbox handle

Open "atl" For DLL As #atl
CallDLL #atl, "AtlAxWinInit", Ret As long

callDLL #user32, "GetWindowLongA", _
hWndContainer as ulong, _
_GWL_HINSTANCE as long, _
hInst as ulong

ResName$ = ReservedWordPage$

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, _ 'URL, or progID or CLSID -file name
style As long, _ 'window style
0 As long, _ 'left x pos
0 As long, _ 'top y pos
408 As long, _ 'width
168 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
return

Initial submission Version 1.0

 ' LB Help Search entry 
' Author: jaba
' Date: May 5, 2011
'
' History:
' v1.0 May 6, 2011 Submitted
'
'
' This code is free for personal use.
'
' 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.
'
' This is a basic and minimum interface which uses the default browser
' to display search terms. As I learn more, I may include a browser control
' in the interface, which I think is the best and fastest way to display
' the search terms. But, for now, I'm happy to be making a submission.
'
' To display the Reserved Word List, I edited the .htm file and saved it
' as a .txt file in my /HTML/ sub folder. The user will see the html
' file in the lower textbox, which includes html tags. I have not made a
' parser yet, or included the browser control to display html files.
' At this point, it's an idea only.
'

HelpDir$ = StartupDir$ + "lb4help\LibertyBASIC_4_web\HTML\"
ReservedWordPage$ = HelpDir$ + "libe6ldg.htm"'"libe6ldg.txt"
HelpFileIndex$ = StartupDir$; "lb4help\LibertyBASIC_4.html"


nomainwin
WindowWidth = 442
WindowHeight = 520
UpperLeftX = DisplayWidth - WindowWidth
UpperLeftY = 40

statictext #s.search "Search for: ", 10, 15, 200, 20
textbox #s.term 10, 35, 320, 25
button #s.default "Find", [getIt], UL, 340, 35, 80, 25
listbox #s.pages, found$(), [ListPages], 10, 65, 410, 200
statictext #s.heading "Commands and Reserved Word List", 10, 270, 300, 20
stylebits #s.reserved, _WS_VSCROLL, _ES_AUTOHSCROLL, 0, 0
textbox #s.reserved 10, 290, 410, 170
button #s.content "Contents", [startBrowser], UL, 340, 5, 80, 25



open "Search Me!" for dialog_nf as #s
#s "trapclose [quit]"

#s.content "!font ms_sans_serif 9 bold"
#s.search "!font ms_sans_serif 9 bold"
#s.heading "!font ms_sans_serif 9 bold"
#s.reserved "!font courier_new 8"

#s.reserved ReservedWordList$(ReservedWordPage$)
#s.term "!setfocus"

dim info$(10,10)
files HelpDir$, "*.htm", info$()

numFiles = val(info$(0,0))
wait

[getIt]
#s.term "!contents? term$"

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
wait

[ListPages]
#s.pages "selection? FileName$"
FileName$ = word$(FileName$, 2, chr$(0))

run "rundll32.exe url.dll,FileProtocolHandler "; chr$(34); HelpDir$; FileName$; chr$(34)

wait

[startBrowser]
run "rundll32.exe url.dll,FileProtocolHandler "; chr$(34); HelpFileIndex$; chr$(34)
#s.term "!setfocus"
wait



[quit]
'How can I close browser window programmatically?
notice "Be sure to close browser!"
close #s
end

'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


function ReservedWordList$(page$)
open page$ for input as #file
ReservedWordList$ = INPUT$(#file, lof(#file))
close #file
end function