udfArrayFindWinItemNameId
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfArrayFindWinItemNameId (strWindowTitlePattern, intArrayDim)
arrWindowList = Arrayize (WinItemNameId (), "|")
intItem = 0
While intItem < ArrInfo (arrWindowList, 1)
   If StrIndexWild (arrWindowList[intItem], strWindowTitlePattern, 1) > 0
      intItem = intItem + 2
   Else
      ArrayRemove (arrWindowList, intItem)
      ArrayRemove (arrWindowList, intItem)
   EndIf
EndWhile
If intArrayDim == 2
   ArrayRedim (arrWindowList, intItem, 2)
   intItem = intItem - 1
   While intItem > 0
      arrWindowList[intItem - 1, 1] = arrWindowList[intItem, 0]
      ArrayRemove (arrWindowList, intItem, 1)
      intItem = intItem - 2
   EndWhile
EndIf
Return arrWindowList
;..........................................................................................................................................
; This UDF "udfArrayFindWinItemNameId" returns an array of WinTitle and WinID values ...
; ... for all windows, whose title matches to the specified wildcard pattern.
;
; strWindowTitlePattern ... Search pattern, in the wildcard pattern, "*" matches zero or more characters, and "?" matches any one character.
; intArrayDim  ............ Determines whether a Dim-1 or a Dim-2 array should be created.
;
; Dim-1 array, field structure:
;    arrWindowList[0] ... WinTitle
;    arrWindowList[1] ... WinID
;    arrWindowList[2] ... WinTitle
;    arrWindowList[3] ... WinID
;    ... and so forth.
;
; Dim-2 array, field structure:
;    arrWindowList[0, 0] ... WinTitle
;    arrWindowList[0, 1] ... WinID
;    arrWindowList[1, 0] ... WinTitle
;    arrWindowList[1, 1] ... WinID
;    ... and so forth.
;
; (c)Detlev Dalitz.20111122.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineSubRoutine udfDisplayResult (intDim)
strList = ""
If intMatches
   strFileOut = ItemReplace ("out.txt", -1, IntControl (1004, 0, 0, 0, 0), ".")
   Switch intDim
   Case 1
      ArrayFilePut (strFileOut, arrResult)
      intMatches = intMatches / 2
      Break
   Case 2
      ArrayFilePutCSV (strFileOut, arrResult)
      Break
   Case intDim
      FilePut (strFileOut, "<empty>")
   EndSwitch
   strList = FileGet (strFileOut)
   FileDelete (strFileOut)
EndIf
strMsgTitle = "udfArrayFindWinItemNameId"
strMsgText = "Pattern = " : strWindowTitlePattern : @LF : "Matches found = " : intMatches : @LF : @LF : strList
Pause (strMsgTitle, strMsgText)
#EndSubRoutine
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.
DirChange (DirScript ())

; Create Dim-1 array.
intArrDim = 1

; No Wildcard - case insensitive, search anywhere in the title.
strWindowTitlePattern = "SysFader"
arrResult = udfArrayFindWinItemNameId (strWindowTitlePattern, intArrDim)
intMatches = ArrInfo (arrResult, 1)
udfDisplayResult (intArrDim)

; Embedded Wildcard - case insensitive, search anywhere in the title.
strWindowTitlePattern = "f*d*r"
arrResult = udfArrayFindWinItemNameId (strWindowTitlePattern, intArrDim)
intMatches = ArrInfo (arrResult, 1)
udfDisplayResult (intArrDim)

; No Match Found.
strWindowTitlePattern = "*@(*(#*&#(*@&*"
arrResult = udfArrayFindWinItemNameId (strWindowTitlePattern, intArrDim)
intMatches = ArrInfo (arrResult, 1)
udfDisplayResult (intArrDim)


; Create Dim-2 array.
intArrDim = 2

; No Wildcard - case insensitive, search anywhere in the title.
strWindowTitlePattern = "SysFader"
arrResult = udfArrayFindWinItemNameId (strWindowTitlePattern, intArrDim)
intMatches = ArrInfo (arrResult, 1)
udfDisplayResult (intArrDim)

; Embedded Wildcard - case insensitive, search anywhere in the title.
strWindowTitlePattern = "f*d*r"
arrResult = udfArrayFindWinItemNameId (strWindowTitlePattern, intArrDim)
intMatches = ArrInfo (arrResult, 1)
udfDisplayResult (intArrDim)

; No Match Found.
strWindowTitlePattern = "*@(*(#*&#(*@&*"
arrResult = udfArrayFindWinItemNameId (strWindowTitlePattern, intArrDim)
intMatches = ArrInfo (arrResult, 1)
udfDisplayResult (intArrDim)

:CANCEL
Exit