WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Control Manager
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Find Text in Window


Question:

Please provide a similar function like Visual Test FndWndC(strText, strClass, wFlags, timeout). This function find a specific text (strText) in windows. Return TRUE if found any text with strText. wFlags can setup for focus or others.

Answer:

;WFndWnd("Digital Signature Not Found", FW_Focus, 2) 
;- Parameters
;(WindowName, Focus after found, timeout)

;WFndWndC("License Agreement", "Static", FW_Focus, 20)
;- Find string in a window
;- Parameters
;(string to find, class name, focus after found, timeout)


AddExtender("wwctl44i.dll")   ; add to top of script someplace


#DefineFunction WFndWnd(WindowName, Focus_after_found, timeout)  ; returns NON-ZERO if found
   found=@FALSE
   For t=0.5 To timeout By 0.5
      If WinExist(WindowName)==@TRUE
         If (Focus_After_Found & 1) == 1
            WinActivate(WindowName)
         EndIf
         found=@TRUE
         Break
      Else
         TimeDelay(0.5)
      EndIf
   Next
   Return(found)
#EndFunction




;#DefineFunction WFndWndC(string_to_find, class_name, focus_after_found, timeout)  ; returns NON-ZERO if found
;   handle=0
;   for t=0.5 to timeout by 0.5
;      handle=CheckWindows(0, string_to_find, class_name)
;      if handle !=0
;          if focus_after_found &1 == 1
;             cSetFocus(handle)
;             break
;          endif
;      endif
;      TimeDelay(0.5)
;   next
;   return(handle)
;#EndFUnction


#DefineFunction WFndWndC(string_to_find, class_name, focus_after_found, timeout)  ; returns NON-ZERO if found
   For t=0.5 To timeout By 0.5
      parentlist=WinItemNameId()
      parentcount=ItemCount(parentlist,"|")
      For p=2 To parentcount By 2   ; pick off winIDs
         aaawindowname=ItemExtract(p-1,parentlist,"|")
         thiswinid=ItemExtract(p,parentlist,"|")
         If WinState(thiswinid)<=0 Then Continue
         hwnd=DllHwnd(thiswinid)
         handle=CheckWindows(hwnd, string_to_find, class_name)
         If handle !=0
            If focus_after_found &1 == 1
               WinActivate(thiswinid)
               Break
            EndIf
            Return(handle)
         EndIf
      Next
      TimeDelay(0.5)
   Next
   Return(0)
#EndFunction





#DefineFunction CheckWindows(handle, string_to_find, class_name)
   If handle==0
      moi=DllHwnd("")
      handle=cWndinfo(moi,4)
   EndIf

   While handle!=0
         classcheck=1
         If class_name != "" Then  If StriCmp(cWndinfo(handle,2),class_name)!=0 Then classcheck=0
         stringcheck=1
         If string_to_find != "" Then  If StriCmp(cWndinfo(handle,0),string_to_find)!=0 Then stringcheck=0
         If (classcheck==1) && (stringcheck==1) Then Return(handle)
         ;Check children of this window
         childfirst=cWndinfo(handle,8)
         If childfirst != 0 Then foundhandle=CheckWindows(childfirst, string_to_find, class_name)
                            Then If foundhandle !=0 Then Return(foundhandle)

         ; check siblings of this window
         handle=cWndinfo(handle,6)  ; get next sibling

   EndWhile

   Return(0)

#EndFunction



; testing

;x= WFndWnd("Missing", 1, 5)    ; title,focus,timeout
;Message("X",x)

y=WFndWndC("LALA", "", 0, 1) 
Message("Y",y)



Article ID:   W16824
File Created: 2007:07:03:14:26:24
Last Updated: 2007:07:03:14:26:24