Try this..
Code:
; Found := 0 ;<= not needed since var's start out blank..
FiletoRead = C:\Temp\File.txt
Gui, Font, S10 CDefault, Verdana
Gui, add, text,,Enter the Search Pattern:
Gui, add, edit, vPattern,
Gui, add, button, default, OK
Gui, show,, Word searcher
Return
GuiEscape:
GuiClose:
Gui, Destroy
ExitApp
ButtonOK:
Gui, Submit
Gui, Destroy
Loop, Read, %FiletoRead%
{
If InStr(A_LoopReadLine, Pattern) ;--if found.. add to 'Found' list..
Found .= Found ? "`n" . A_LoopReadLine | A_LoopReadLine
}
If Found {
Gui, 2:Font, S12 CDefault, Courier New
Loop, Parse, Found, `n ;--add each line in 'Found' as a gui text..
Gui, 2:add, text,Center,%A_LoopField%
Gui, 2:show,, Password searcher ;--show your new gui..
Return
} Else {
MsgBox, 48,Warning - Word searcher, Nothing Found!
ExitApp
}
2GuiEscape:
2GuiClose:
Gui, Destroy
ExitApp
Notice how it doesn't show the new gui until after it adds all the matches.
Here is another example that uses one gui to show all the results in a
ListView control.
Code:
FileRead, FileVar, C:\Temp\File.txt ;--read to var..
Gui, Font, S10 CDefault, Verdana
Gui, Add , Text , , Enter the Search Pattern:
Gui, Add , Edit , Section gPattern,
Gui, Add , ListView, xs vResults, Results
Gui, Show, , Word searcher
Return
Pattern:
LV_Delete() ;--clears previous results..
If !A_GuiControl ;--(A_GuiControl contains contents of edit field..)
return
Loop, Parse, FileVar, `n, `r
If RegExMatch( A_LoopField, "^" . A_GuiControl ) ;-adds matches to Listview..
LV_Add("", A_LoopField )
return