' LB Help Search Add-on.bas' Author: Stefan Pendl' Date: 24.04.11'' Copyright 2011 by Stefan Pendl'' This code is free for personal use.' 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 author'' The ATL control code is based on code at http://lbpe.wikispaces.com/ATL+Tutorial''' Credits:' Thanks to Alyce, Janet, Chris, Rod, Jack for inspiring me.' Thanks to the LB community for giving me the opportunity to learn and exchange code.''' History:'' v1.0.0 ... April 24th, 2011 ... Initial release' v1.0.1 ... April 25th, 2011 ... moved index initialization after opening the window' v1.0.2 ... -"- ... added static text control, if ATL failed to initialize' v1.0.3 ... April 26th, 2011 ... added selection of "exact phrase", "all words" or "any word"' v1.0.4 ... -"- ... added function to build search pattern, source restructured' v1.0.5 ... -"- ... added selection of "index only", "page contents" or "source code"' v1.0.6 ... April 28th, 2011 ... added custom resize handler, since native one is only for type window' v1.0.7 ... April 30th, 2011 ... added Index button to display initial page and index of all pages' added Usage button to display general usage of this application' resizer and ATL control are now DPI aware' v1.0.8 ... -"- ... current settings and window layout are saved on close' v1.0.9 ... May 1st, 2011 ... making sure the ini file destination folder exists' save window layout without scaling' v1.0.10 ... May 2nd, 2011 ... now using a text box instead of the static text control to allow scroll bars' added more comments in preparation of the final release' v1.0.11 ... May 7th, 2011 ... added credits' update list box for each found page during the search' v1.0.12 ... May 8th, 2011 ... reverted back to Quick Start page as initial page' v1.0.13 ... -"- ... added hint about ATL context menu for printing' v1.0.14 ... May 15th, 2011 ... reverted back to index page as initial page'' Todo:' # nothing left to do ;-)' ################################' ################################' ## ##' ## section for initialization ##' ## ##' ################################' ################################' check for valid LB versionifval(Version$)<4.04thennotice"Wrong LB Version!"; chr$(13);_
"This add-on is only valid for LB v4.04 and above!"; chr$(13);_
"Exiting ..."endendif[InitVars]' initialize variables
LbInstallDir$ = GetFolder$(GetModuleFileName$())
HelpFileRoot$ = LbInstallDir$; "lb4help\LibertyBASIC_4_web\html\"
HelpFileIndex$ = LbInstallDir$; "lb4help\LibertyBASIC_4.html"
HelpFilePattern$ ="*.htm"
InitialTitle$ ="Index"
InitialPage$ = HelpFileIndex$
' variables for the ini file
AppDataFolder$ = GetEnvironmentVariable$("APPDATA")
LbAppDataFolder$ = GetPathTail$(LbInstallDir$)
IniFileName$ ="LB Help Search Add-on.ini"
ResizerDelay =250dim FilesInfo$(1,1), PageIndex$(1,2), FoundPages$(1)' initialize ATL controlOpen"atl"ForDLLAs#atl
CallDLL#atl,"AtlAxWinInit", ATLinitialized Aslong' ######################################' ######################################' ## ##' ## section for user interface setup ##' ## ##' ######################################' ######################################[GUI]' setup GUInomainwinWindowWidth=800WindowHeight=600UpperLeftX=DisplayWidth-WindowWidthUpperLeftY=1' minimum window size
MinWindowWidth =int(500* GetScreenScaleForDialog())
MinWindowHeight =int(400* GetScreenScaleForDialog())' default size for ATL/text box control
DefaultAtlPosX =210
DefaultAtlPosY =10
DefaultAtlWidth =575
DefaultAtlHeight =550' default settings of the radio buttons
AsPhrase$ ="set"
AllWords$ ="reset"
AnyWord$ ="reset"
IndexOnly$ ="set"
PageContents$ ="reset"
SourceCode$ ="reset"' get the saved layout and settings from the ini filegosub[ReadDefaults]' define the GUI
WindowTitle$ ="LB Help Search"groupbox#m.search,"Search Text",5,5,200,95textbox#m.phrase,15,20,180,25radiobutton#m.AsPhrase,"As Phrase",[nothing],[nothing],15,50,90,20radiobutton#m.AllWords,"All Words",[nothing],[nothing],105,50,90,20radiobutton#m.AnyWord,"Any Word",[nothing],[nothing],15,70,90,20groupbox#m.source,"Search Source",5,105,200,65radiobutton#m.IndexOnly,"Index Only",[nothing],[nothing],15,120,90,20radiobutton#m.PageContents,"Page Contents",[nothing],[nothing],105,120,90,20radiobutton#m.SourceCode,"Source Code",[nothing],[nothing],15,140,90,20button#m.default,"Search",[DoSearch], ul,5,175,60,25button#m.index,"Index",[Index], ul,75,175,60,25button#m.usage,"Usage",[Usage], ul,145,175,60,25groupbox#m.result,"Search Results",5,205,200,355stylebits#m.pages, _WS_HSCROLL,0,0,0listbox#m.pages, FoundPages$(),[DisplayPage],15,222,180,325' create the ATL or a text box controlif ATLinitialized then
AtlPosX =int(DefaultAtlPosX * GetScreenScaleForDialog())
AtlPosY =int(DefaultAtlPosY * GetScreenScaleForDialog())
AtlWidth =int(DefaultAtlWidth * GetScreenScaleForDialog())
AtlHeight =int(DefaultAtlHeight * GetScreenScaleForDialog())else
AtlPosX = DefaultAtlPosX
AtlPosY = DefaultAtlPosY
AtlWidth = DefaultAtlWidth
AtlHeight = DefaultAtlHeight
' the text box will be read-only and include scroll barsstylebits#m.info, _ES_READONLY or _WS_VSCROLL or _WS_HSCROLL, _ES_AUTOHSCROLL or _ES_AUTOVSCROLL,0,0textbox#m.info, AtlPosX, AtlPosY, AtlWidth, AtlHeight
endif' create a dilog with a sizing frame and a minimize boxstylebits#m, _WS_THICKFRAME or _WS_MINIMIZEBOX,0,0,0open WindowTitle$; " - "; InitialTitle$ fordialogas#m
#m "trapclose [quit]"cursor hourglass
if ATLinitialized then
Message$ ="MSHTML:<html><head></head><body><center><h1>Initializing index!";_
"<br/>Please wait ...</h1></center></body></html>"
hATL = DisplayATL("#m", Message$, hATL, AtlPosX, AtlPosY, AtlWidth, AtlHeight)else#m.info "!font 20 bold"#m.info "Initializing index!"; chr$(13); "Please wait ..."endif' create page indexgosub[CreateIndex]' preset controls#m.phrase " Enter Search Text "#m.pages "singleclickselect"#m.AsPhrase AsPhrase$
#m.AllWords AllWords$
#m.AnyWord AnyWord$
#m.IndexOnly IndexOnly$
#m.PageContents PageContents$
#m.SourceCode SourceCode$
#m.pages "reload"#m.default "!setfocus"#m.phrase "!setfocus"' select entire text in the search box
Handle =hwnd(#m.phrase)calldll#user32,"SendMessageA",_
Handle asulong,_
_EM_SETSEL asulong,_
0aslong,_
-1asulong,_
result aslongcursor normal
OldWidth =-1
OldHeight =-1timer ResizerDelay,[resizer]' invoke initial resizinggoto[resizer]' ################################' ################################' ## ##' ## section for event handlers ##' ## ##' ################################' ################################[nothing]' dummy event handler for the radio buttonswait[Index]' event handler for the index button
OverridePhrase =1[DoSearch]' event handler for the search and index buttonscursor hourglass
timer0' clear the list box arrayredim FoundPages$(FoundFiles)#m.phrase "!contents? Phrase$"if Phrase$ =""or OverridePhrase =1thenfor i =1to FoundFiles
FoundPages$(i)= PageIndex$(i,1); chr$(0); PageIndex$(i,2)nextelse#m.AsPhrase "value? AsPhrase$"#m.AllWords "value? AllWords$"#m.AnyWord "value? AnyWord$"#m.IndexOnly "value? IndexOnly$"#m.PageContents "value? PageContents$"#m.SourceCode "value? SourceCode$"' build the dynamic search conditionselectcasecase AnyWord$ ="set"
SearchPattern$ = BuildSearchPattern$(Phrase$,"contents$","OR",0)case AllWords$ ="set"
SearchPattern$ = BuildSearchPattern$(Phrase$,"contents$","AND",0)caseelse
SearchPattern$ ="instr(upper$(contents$), upper$(Phrase$)) > 0"endselect' cycle through the pages
j =1for i =1to FoundFiles
selectcasecase SourceCode$ ="set"
contents$ = CollectSourceCode$(PageIndex$(i,2))case PageContents$ ="set"open PageIndex$(i,2)forinputas#f
contents$ =input$(#f,lof(#f))close#f
caseelse
contents$ = PageIndex$(i,1)endselectifeval(SearchPattern$)then
FoundPages$(j)= PageIndex$(i,1); chr$(0); PageIndex$(i,2)
j = j +1#m.pages "reload"endifnextendif#m.pages "reload"#m.pages "selectindex 0"#m.phrase "!setfocus"#m.default "!setfocus"cursor normal
timer ResizerDelay,[resizer]' wait here if the search button was hit, continue for the index buttonif OverridePhrase =0thenwait[DisplayPage]' event handler for the selected list box item and the index buttonif OverridePhrase =1then
Page$ = InitialTitle$; chr$(0); InitialPage$
else#m.pages "selection? Page$"endif
FileName$ =word$(Page$,2,chr$(0))if ATLinitialized then
hATL = DisplayATL("#m", FileName$, hATL, AtlPosX, AtlPosY, AtlWidth, AtlHeight)else#m.info "!font 20 bold"#m.info "Displaying Pages in your Browser!"run"rundll32.exe url.dll,FileProtocolHandler "; chr$(34); FileName$; chr$(34)endifcall SetWindowText "#m", WindowTitle$; " - "; word$(Page$,1,chr$(0)); chr$(0)
OverridePhrase =0wait[resizer]' resize handler for the dialog window' get window sizecall GetWindowRect "#m",UpperLeftX,UpperLeftY,WindowWidth,WindowHeight' check if we match the minimum sizeifWindowWidth< MinWindowWidth thenWindowWidth= MinWindowWidth
ifWindowHeight< MinWindowHeight thenWindowHeight= MinWindowHeight
' get desktop sizeif GetDesktopRect(DesktopPosX, DesktopPosY, DesktopWidth, DesktopHeight)=1then' check if we are out of boundsif(UpperLeftX+WindowWidth)>(DesktopPosX + DesktopWidth)thenUpperLeftX= DesktopPosX + DesktopWidth -WindowWidthendififUpperLeftX< DesktopPosX thenUpperLeftX= DesktopPosX
if(UpperLeftY+WindowHeight)>(DesktopPosY + DesktopHeight)thenUpperLeftY= DesktopPosY + DesktopHeight -WindowHeightendififUpperLeftY< DesktopPosY thenUpperLeftY= DesktopPosY
' check if we exceed the desktop sizeifWindowWidth> DesktopWidth thenWindowWidth= DesktopWidth
ifWindowHeight> DesktopHeight thenWindowHeight= DesktopHeight
endifcall SetWindowPos hwnd(#m),UpperLeftX,UpperLeftY,WindowWidth,WindowHeight' get client area sizeif GetClientRect("#m", NewWidth, NewHeight)=0thenwait' check if size has changedif NewWidth = OldWidth and NewHeight = OldHeight thenwait' resize controlscall SetWindowPos hwnd(#m.pages),-1,-1,int(180* GetScreenScaleForDialog()),_
NewHeight -int((222+20)* GetScreenScaleForDialog())call SetWindowPos hwnd(#m.result),-1,-1,int(200* GetScreenScaleForDialog()),_
NewHeight -int((205+10)* GetScreenScaleForDialog())if ATLinitialized then
hBrowse = hATL
AtlWidth = NewWidth - AtlPosX -int(10* GetScreenScaleForDialog())else
hBrowse =hwnd(#m.info)#m.info "!contents? hBrowseCaption$"
AtlWidth = NewWidth -int((AtlPosX +10)* GetScreenScaleForDialog())endif
AtlHeight = NewHeight - AtlPosY -int(10* GetScreenScaleForDialog())call SetWindowPos hBrowse,-1,-1, AtlWidth, AtlHeight
' refresh text box contentsifnot(ATLinitialized)then#m.info ""#m.info hBrowseCaption$
endif' remember current size to avoid running the entire handler, if nothing changed
OldWidth = NewWidth
OldHeight = NewHeight
wait[Usage]' event handler for the usage buttonif UsageMessage$ =""thenrestore[UsageMessage]' use an infinite loop to read the usage messagewhile1read String$
' break the loop, if we have reached the end of the message definitionif String$ ="@END"thenexitwhile' filter strings valid only for the ATL controlifleft$(String$,4)="ATL:"thenif ATLinitialized then
UsageMessage$ = UsageMessage$ +mid$(String$,5)else
String$ =""endifelse' replace "\n" by the new-line characters or tagifinstr(String$,"\n")>0thenif ATLinitialized then' filter strings valid only for the static text controlifleft$(String$,7)="STATIC:"then
String$ =""else
String$ ="<br/>"endifelse
String$ =chr$(13); chr$(10)endifendif' concatenate the message into one long string for easier display
UsageMessage$ = UsageMessage$ + String$
endifwendendifif ATLinitialized then
hATL = DisplayATL("#m", UsageMessage$, hATL, AtlPosX, AtlPosY, AtlWidth, AtlHeight)else#m.info "!font courier_new 10"#m.info UsageMessage$
endif#m.default "!setfocus"wait[quit]' event handler for closing the dialoggosub[SaveDefaults]close#m
Close#atl
end' #################################' #################################' ## ##' ## section for DATA definition ##' ## ##' #################################' #################################[UsageMessage]' definition of the usage message'' strings starting with "ATL:" are only valid for the ATL control' strings starting with "STATIC:" are only valid for the static text control' strings containing "\n" are replaced by new line characters or tagsdata"ATL:MSHTML:<html><head><title>Usage</title></head><body>"data"ATL:<center><h3>","LB Help Search Add-On - Usage","ATL:</h3></center>","STATIC:\n","STATIC:\n"data"ATL:<h4>","Search Text:","ATL:</h4>","STATIC:\n","STATIC:\n"data"ATL:<pre>"data"Text field ... enter text to search for","\n"data"As Phrase .... results containing the entered words as is","\n"data"All Words .... results containing all entered words","\n"data"Any Word ..... results containing at least one of the entered words","\n"data"ATL:</pre>"data"STATIC:\n"data"ATL:<h4>","Search Source:","ATL:</h4>","STATIC:\n","STATIC:\n"data"ATL:<pre>"data"Index Only ...... search only the title of the pages","\n"data"Page Contents ... search the entire page content","\n"data"Source Code ..... search only example code contained on the pages","\n"data"ATL:</pre>"data"STATIC:\n"data"ATL:<h4>","Buttons:","ATL:</h4>","STATIC:\n","STATIC:\n"data"ATL:<pre>"data"Search ... start the search according to the above settings","\n"data"Index .... display the initial page and load the list of all pages","\n"data"Usage .... display this message","\n"data"ATL:</pre>"data"STATIC:\n"data"ATL:<h4>","Search Results:","ATL:</h4>","STATIC:\n","STATIC:\n"data"ATL:<pre>"data"Initially ........ contains the list of all pages","\n"data"After a Search ... contains the list of matching pages","\n"data"ATL:</pre>"data"ATL:<h4>","ATL:Printing can be done through the context menu of this control.","ATL:</h4>"data"STATIC:\n"data"ATL:<h4>","Settings and window layout are saved on close.","ATL:</h4>"data"ATL:</body></html>"data"@END"' ############################' ############################' ## ##' ## section for procedures ##' ## ##' ############################' ############################' ##########' # #' # GOSUBs #' # #' ##########[SaveDefaults]' save dialog layout and current settings to the ini file#m.AsPhrase "value? AsPhrase$"#m.AllWords "value? AllWords$"#m.AnyWord "value? AnyWord$"#m.IndexOnly "value? IndexOnly$"#m.PageContents "value? PageContents$"#m.SourceCode "value? SourceCode$"' make sure the destination folder exists
result =mkdir(AppDataFolder$; "\"; LbAppDataFolder$)' save the settings only if the folder was created or already existsif result =0or result =183thencall GetWindowRect "#m",UpperLeftX,UpperLeftY,WindowWidth,WindowHeightifUpperLeftX=0thenUpperLeftX=1ifUpperLeftY=0thenUpperLeftY=1open AppDataFolder$; "\"; LbAppDataFolder$; "\"; IniFileName$ foroutputas#ini
#ini "WindowWidth = "; int(WindowWidth/ GetScreenScaleForDialog())#ini "WindowHeight = "; int(WindowHeight/ GetScreenScaleForDialog())#ini "UpperLeftX = "; UpperLeftX#ini "UpperLeftY = "; UpperLeftY#ini "AsPhrase = "; AsPhrase$
#ini "AllWords = "; AllWords$
#ini "AnyWord = "; AnyWord$
#ini "IndexOnly = "; IndexOnly$
#ini "PageContents = "; PageContents$
#ini "SourceCode = "; SourceCode$
close#ini
elsenotice"Path does not exist"; chr$(13); "Unable to save settings!"endifreturn[ReadDefaults]' read dialog layout and last settings from the ini filefiles AppDataFolder$; "\"; LbAppDataFolder$, IniFileName$, FilesInfo$()' only read if file existsifval(FilesInfo$(0,0))>0thenopen AppDataFolder$; "\"; LbAppDataFolder$; "\"; IniFileName$ forinputas#ini
whilenot(eof(#ini))lineinput#ini, setting$
Option$ =trim$(word$(setting$,1,"="))
Value$ =trim$(word$(setting$,2,"="))selectcase Option$
case"WindowWidth"WindowWidth=val(Value$)case"WindowHeight"WindowHeight=val(Value$)case"UpperLeftX"UpperLeftX=val(Value$)case"UpperLeftY"UpperLeftY=val(Value$)case"AsPhrase"
AsPhrase$ = Value$
case"AllWords"
AllWords$ = Value$
case"AnyWord"
AnyWord$ = Value$
case"IndexOnly"
IndexOnly$ = Value$
case"PageContents"
PageContents$ = Value$
case"SourceCode"
SourceCode$ = Value$
endselectwendclose#ini
endifreturn[CreateIndex]' fill page indexfiles HelpFileRoot$, HelpFilePattern$, FilesInfo$()
FoundFiles =val(FilesInfo$(0,0))if FoundFiles =0thenif ATLinitialized then
Message$ ="MSHTML:<html><head></head><body><center><h1>Unable to locate Help Files!";_
"</h1></center></body></html>"
hATL = DisplayATL("#m", Message$, hATL, AtlPosX, AtlPosY, AtlWidth, AtlHeight)else#m.info "Unable to locate Help Files!"endifelseredim PageIndex$(FoundFiles,2)redim FoundPages$(FoundFiles)for i =1to FoundFiles
FileName$ = HelpFileRoot$; FilesInfo$(i,0)open FileName$ forinputas#f
contents$ =input$(#f,min(512,lof(#f)))close#f
' parsing the tilte tag does not return unique results' StartPos = instr(upper$(contents$), "<TITLE>") + 7' EndPos = instr(upper$(contents$), "</TITLE>, StartPos")' parsing the first bold text does return unique results' this returns the headline
StartPos =instr(upper$(contents$),"<B>")+3
EndPos =instr(upper$(contents$),"</B>", StartPos)
PageTitle$ =mid$(contents$, StartPos, EndPos - StartPos)
PageIndex$(i,1)= PageTitle$
PageIndex$(i,2)= FileName$
next' sort page indexsort PageIndex$(,1, FoundFiles,1' fill list box array with page informationfor i =1to FoundFiles
FoundPages$(i)= PageIndex$(i,1); chr$(0); PageIndex$(i,2)nextif ATLinitialized then
hATL = DisplayATL("#m", InitialPage$, hATL, AtlPosX, AtlPosY, AtlWidth, AtlHeight)else#m.info "Displaying Pages in your Browser!"endifcall SetWindowText "#m", WindowTitle$; " - "; InitialTitle$; chr$(0)endifreturn' ########' # #' # SUBs #' # #' ########sub SetWindowPos hWndParent, PosX, PosY, Width, Height
' set window position and size with the ability to ignore one or the other'' hWndParent ... handle of the control to position/resize' PosX ......... horizontal position of the top left corner' PosX ......... vertical position of the top left corner' Width ........ new width of the control or window' Height ....... new height of the control or window' do not change the z-order and do not activate the window/control
uFlags = _SWP_NOZORDER or _SWP_NOACTIVATE
' ignore the positional arguments, if both are -1if PosX =-1and PosY =-1then uFlags = uFlags or _SWP_NOMOVE
' ignore the size arguments, if both are -1if Width =-1and Height =-1then uFlags = uFlags or _SWP_NOSIZE
calldll#user32,"SetWindowPos",_
hWndParent asulong,_
_NULL asulong,_
PosX aslong,_
PosY aslong,_
Width aslong,_
Height aslong,_
uFlags asulong,_
result aslongendsubsub GetWindowRect Parent$,ByRef PosX,ByRef PosY,ByRef Width,ByRef Height
' get the size of the window or control'' Parent$ ... LB handle of the control or window, for instance "#m" or "#m.cb"'' on success fills the remaining 4 arguments with the' size and position of the control/window
hWndParent =hWnd(#Parent$)struct RECT,_
left asLONG,_
top asLONG,_
right asLONG,_
bottom asLONGcalldll#user32,"GetWindowRect",_
hWndParent asulong,_
RECT asstruct,_
result aslongif result <>0then
PosX = RECT.left.struct
PosY = RECT.top.struct
Width = RECT.right.struct- RECT.left.struct
Height = RECT.bottom.struct- RECT.top.structendifendsubsub SetWindowText Parent$, Caption$
' change the caption of a control or window'' Parent$ .... LB handle of the control or window, for instance "#m" or "#m.cb"' Caption$ ... text for the new caption
hWndParent =hWnd(#Parent$)calldll#user32,"SetWindowTextA",_
hWndParent asulong,_
Caption$ asptr,_
result aslongendsub' #############' # #' # FUNCTIONs #' # #' #############function GetClientRect(Parent$,ByRef Width,ByRef Height)' get the size of a window'' Parent$ .... LB handle of the window, for instance "#m"'' on success 1 is returned and the arguments are filled with the values' on failure 0 is returned
hWndParent =hWnd(#Parent$)struct RECT,_
left asLONG,_
top asLONG,_
right asLONG,_
bottom asLONGcalldll#user32,"GetClientRect",_
hWndParent asulong,_
RECT asstruct,_
result aslongif result <>0then
Width = RECT.right.struct
Height = RECT.bottom.struct
GetClientRect =1else
GetClientRect =0endifendfunctionfunction GetDesktopRect(ByRef PosX,ByRef PosY,ByRef Width,ByRef Height)' get the size and position of the desktop area not covered by any tool bars'' on success 1 is returned and the arguments are filled with the values' on failure 0 is returnedstruct RECT,_
left asLONG,_
top asLONG,_
right asLONG,_
bottom asLONG
uiAction = _SPI_GETWORKAREA
calldll#user32,"SystemParametersInfoA",_
uiAction asulong,_
uiParam asulong,_
RECT asstruct,_
fWinIni asulong,_
result aslongif result <>0then
PosX = RECT.left.struct
PosY = RECT.top.struct
Width = RECT.right.struct- RECT.left.struct
Height = RECT.bottom.struct- RECT.top.struct
GetDesktopRect =1else
GetDesktopRect =0endifendfunctionfunction CollectSourceCode$(FileName$)' this function parses HTML pages for source code sections' and returns a concatenated string of them' source code in LBs help file is defined by the font "Courier New"
StartCode$ ="<FONT FACE="; chr$(34); "COURIER NEW"; chr$(34); " SIZE="; chr$(34); "2"; chr$(34); ">"open FileName$ forinputas#f
contents$ =input$(#f,lof(#f))close#f
StartPos =0
EndPos =1' use an infinite loop for parsingwhile1
StartPos =instr(upper$(contents$), StartCode$, EndPos)' break out of the loop, if there is nothing foundif StartPos =0thenexitwhile
StartPos = StartPos +len(StartCode$)
EndPos =instr(upper$(contents$),"</FONT>", StartPos)
CollectSourceCode$ = CollectSourceCode$; "<br/>"; mid$(contents$, StartPos, EndPos - StartPos)wendendfunctionfunction BuildSearchPattern$(SearchString$, ContainerVar$, Operator$, CaseSensitive)' return a string containing a conditional statement to be executed by the EVAL() function'' SearchString$ ... string containing the search term' ContainerVar$ ... variable containing the string to be searched' Condition$ ...... boolean operator to concatenate multiple conditions (AND/OR/XOR)' CaseSensitive ... flag to create a case sensitive contition or not' 1 ... case sensitive' 0 ... case insensitive
count =1' build condition for first word of the search termif CaseSensitive then
BuildSearchPattern$ ="instr("; ContainerVar$; ", ";_
chr$(34); word$(SearchString$, count); chr$(34); ") > 0"else
BuildSearchPattern$ ="instr(upper$("; ContainerVar$; "), ";_
chr$(34); upper$(word$(SearchString$, count)); chr$(34); ") > 0"endif
count = count +1' add remaining conditions separated by the operatorwhileword$(SearchString$, count)<>""if CaseSensitive then
BuildSearchPattern$ = BuildSearchPattern$; " "; Operator$; " instr("; ContainerVar$; ", ";_
chr$(34); word$(SearchString$, count); chr$(34); ") > 0"else
BuildSearchPattern$ = BuildSearchPattern$; " "; Operator$; " instr(upper$("; ContainerVar$; "), ";_
chr$(34); upper$(word$(SearchString$, count)); chr$(34); ") > 0"endif
count = count +1wendendfunctionfunction DisplayATL(Parent$, File$, Handle, PosX, PosY, Width, Height)' create an ATL control'' Parent$ ... LB handle of the parent window, for instance "#m"' File$ ..... Path of a file, HTML code as a string or an URL' see http://lbpe.wikispaces.com/ATL+Tutorial for more' Handle .... Windows handle of the last created ATL control' usually the handle returned by the last call of this function'' on success returns the handle of the created controlif Handle thenCallDLL#user32,"DestroyWindow", _
Handle Asulong, _
result Aslongendif
hWndParent =hWnd(#Parent$)CallDLL#user32,"GetWindowLongA", _
hWndParent Asulong, _
_GWL_HINSTANCE Aslong, _
hInst Asulong
style = _WS_CHILD or _WS_VISIBLE or _WS_VSCROLL or _WS_HSCROLL or _WS_BORDER
exStyle = _WS_EX_CLIENTEDGE or _WS_EX_TOPMOST
CallDLL#user32,"CreateWindowExA", _
exStyle Asulong, _
"AtlAxWin"Asptr, _
File$ Asptr, _
style Asulong, _
PosX Aslong, _
PosY Aslong, _
Width Aslong, _
Height Aslong, _
hWndParent Asulong, _
_NULL Asulong, _
hInst Asulong, _
_NULL Asulong, _
DisplayATL Asulongendfunctionfunction GetFolder$(Path$)' strip off the part after the last backslash of a file or folder path
pos =1
GetFolder$ = Path$
while pos >0
pos =instr(Path$,"\", pos)if pos >0then
GetFolder$ =left$(Path$, pos)
pos = pos +1endifwendendfunctionfunction GetPathTail$(Path$)' get the part after the last backslash of a file or folder pathifright$(Path$,1)="\"then
GetPathTail$ =left$(Path$,len(Path$)-1)else
GetPathTail$ = Path$
endiffor pos =len(GetPathTail$)to1 step -1ifmid$(GetPathTail$, pos,1)="\"thenexitfornextif pos >1then GetPathTail$ =mid$(GetPathTail$, pos +1)endfunctionfunction GetModuleFileName$()' return the full path of the executable of the current process
nSize = _MAX_PATH +1
lpFilename$ =space$(nSize); CHR$(0)calldll#kernel32,"GetModuleFileNameA",_
hModule asuLong,_
lpFilename$ asptr,_
nSize asuLong,_
result asuLongif result >0then GetModuleFileName$ =trim$(lpFilename$)endfunctionfunction GetScreenScaleForDialog()' get the scale to size controls inside a dialog type window'' controls of dialog type windows are automatically scaled' to match the users screen DPI settings'' LB does not use all scales, only 100% and 125%calldll#user32,"GetDC",_
0asulong,_ ' entire screen
hDC asulong
nIndex = _LOGPIXELSX
calldll#gdi32,"GetDeviceCaps",_
hDC asulong,_
nIndex asulong,_
dpi asulongcalldll#user32,"ReleaseDC",_
0asulong,_ ' entire screen
hDC asulong,_
result asulong' 1 = success
ScreenScale = dpi /96
ScreenScaleTmp =max(1, ScreenScale)
GetScreenScaleForDialog =min(1.25, ScreenScaleTmp)endfunctionfunction GetEnvironmentVariable$(lpName$)'get the value of an environment variable
nSize =1024[Retry]
lpBuffer$ =space$(nSize)calldll#kernel32,"GetEnvironmentVariableA", _
lpName$ asptr, _
lpBuffer$ asptr, _
nSize asulong, _
result asulongselectcase' buffer too smallcase result > nSize
nSize = result
goto[Retry]' variable foundcase result >0
GetEnvironmentVariable$ =trim$(lpBuffer$)endselectendfunction
Download entire LB Pro project (use save target as)
A small screen shot