Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with Wait Statements -for Childwindow and for Acc
#1
Hi ,

I am having trouble with Wait statements.

I would like to wait 60 seconds for a certain dialog to come up. If I do it just by Window Name/Class, there is ambiguity between the window I want to wait for and an earlier window that shares the same Window Name/Class but different content inside.

Code:
Copy      Help
wait 120 WA win("Sample App" "#32770")

If I wait by Controls, it doesn't recognize the wait 60 seconds and throws the wait time-out error immediately - no matter how high I set the seconds.

Code:
Copy      Help
wait 120 WC child("Are you sure you want to sign this report?" "Static" win("SampleApp" "#32770") 0x1)


I also tried doing it as an acc statement with a wait time but that didn't work either.

Code:
Copy      Help
Acc a=acc("Are you sure you want to sign this report?" "WINDOW" win("Commissure RadWhere" "#32770") "Static" "" 0x1001 0 0 "" 120)



This seems like a bug but is probably a syntax error on my part. Any advice?

Thanks,
Stuart
#2
QM does not have a function that waits for a window that has certain child window. It can wait for a window or for a child window in existing window.

Function WaitForWindowWithChild
Code:
Copy      Help
;/
function# ^waitmax $childtext $childclass [childflags] [$wintext] [$winclass] [$exename] [winflags] [&hwndchild] ;;waitmax: 0 is infinite.

;Waits for a window that has the specified child window.
;Returns window handle.


;waitmax - max number of seconds to wait. 0 is infinite.
;childtext, childclass, childflags - same as with function <help "::/functions/IDP_CHILD.html">child</help>.
;other arguments - same as with function <help "::/functions/IDP_WIN.html">win</help>.


;See also: <WinC>

;EXAMPLE
;int h=WaitForWindowWithChild(120 "Are you sure you want to sign this report?" "Static" 0 "SampleApp" "#32770")
;out _s.getwintext(h)



if(waitmax<0 or waitmax>2000000) end ES_BADARG
opt waitmsg -1

int wt(waitmax*1000) t1(GetTickCount)
rep
,0.01
,
,int h=WinC(childtext childclass childflags wintext winclass exename winflags hwndchild)
,if(h) ret h
,
,if(wt>0 and GetTickCount-t1>=wt) end "wait timeout"
#3
Works Great!!!!
Thanks,
Stuart
#4
I tried to do the same thing but instead of a child window the Acc event but it didn't work....

Code:
Copy      Help
Acc a=acc("Are you sure you want to sign this report?" "STATICTEXT" win("SampleApp" "#32770") "Static" "" 0x1001 0 0 "" 5)
if(a.a)
,mes "found it"
if(!a.a)
,mes "didn't find it in time"
,ret

It won't wait the 5 seconds for it to show up but immediately throws the error for not finding the object. It does work if it already on the screen when the macro is run.

I think my problem this time is syntax but I was so impressed how you wrote that function for the previuos question!!!
Thanks!!!!
Stuart
#5
Remove flag 0x1000.

Like wait ... child, acc also waits only in first matching window.

Waiting for accessible object in multiple windows would eat much CPU. Do you really need it when you have WaitForWindowWithChild?
#6
Hi Gintaras,
More just for completeness sake. Your new Function does the trick!
Thanks,
Stuart
#7
cool thx gint
#8
any idea why this wont work
Function Function4
Code:
Copy      Help
int hwnd=val(_command)
str name1 listofnames="item 1[]item 2[]item 3"

;start
Acc a

foreach name1 listofnames
,a=acc(name1 "LINK" hwnd "Internet Explorer_Server" "" 0x1010); err
,str name=a.Name
,if matchw(name name1)
,,out name
,out "1"
#9
What should the macro do? I see what it does, and it is correct (except err), but maybe you need different behavior.
#10
i need the macro to check if the object is there and if it is output the objects name should i use opt err 1 instead of err or different statement. it does not find the objects even though i know they are deffinetly there.
#11
Here acc searches for link containing text "item 1", then "item 2"...
If there are no links containing this text, acc throws error.
Remove err to see what is the error.
Usually, when you handle error with err, you should do something on error, for example
err continue
Otherwise next statement that uses a will throw error or use bad object.
Maybe the window (hwnd) is 0.
#12
it works for qm forum this is full code maybe the site is slow to load.
Function Dialog3
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
str controls = "5 8 10"
str ax3SHD e5 e8
ax3SHD="http://www.quickmacros.com/forum/ucp.php?mode=login"
if(!ShowDialog("Dialog3" &Dialog3 &controls)) ret
;BEGIN DIALOG
;0 "" 0x90CF0AC8 0x0 0 0 222 135 "Dialog"
;1 Button 0x54030000 0x0 0 0 48 14 "a"
;2 Button 0x54032000 0x0 48 0 54 14 "b"
;3 Button 0x54032000 0x0 102 0 72 14 "Scan Name"
;4 Button 0x54032000 0x0 174 0 48 14 "STOP"
;5 ActiveX 0x54030000 0x0 0 0 2 4 "SHDocVw.WebBrowser"
;6 Static 0x54000000 0x0 6 30 212 22 "Please type your log in info, and then click log-in."
;7 Edit 0x54030080 0x200 12 68 190 14 ""
;8 Static 0x54000000 0x0 82 54 48 10 "Username"
;9 Static 0x54000000 0x0 88 86 36 12 "Password"
;10 Edit 0x54030020 0x200 12 100 192 14 ""
;11 Button 0x54032000 0x0 84 116 48 14 "Login"
;END DIALOG
;DIALOG EDITOR: "" 0x2030208 "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_TIMER
,sel 1
,,case 1
,,RECT r;int hwnd0 hwnd1
,,GetWindowRect(hDlg &r)
,,int x y cx cy
,,GetWinXY hDlg x y cx cy
,,MoveWindow id(5 hDlg) x-x y-y r.right-r.left r.bottom-r.top 1
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,ret
,case 3
,_s="http://www.quickmacros.com/forum/index.php"
,_s.setwintext(id(5 hDlg))
,mac "ScanName" hDlg
,case 11
,Acc a
,opt err 1
,0.5
,_s.getwintext(id(7 hDlg))
,a=acc("Username:" "TEXT" hDlg "Internet Explorer_Server" "" 0x1811 0x0 0x20000040)
,a.SetValue(_s)
,_s.getwintext(id(10 hDlg))
,a=acc("Password:" "TEXT" hDlg "Internet Explorer_Server" "" 0x1811 0x20000000 0x20000040)
,a.SetValue(_s)
,0.1
,a=acc("Login" "PUSHBUTTON" hDlg "Internet Explorer_Server" "" 0x1011)
,a.DoDefaultAction
,opt err 0
,SetTimer hDlg 1 700 0
,case IDCANCEL
ret 1

Function ScanName
Code:
Copy      Help
int hwnd=val(_command)
str name1 listofnames="Board index[]Untitled[]QM and Forum Info"

;start
Acc a

foreach name1 listofnames
,a=acc(name1 "LINK" hwnd "Internet Explorer_Server" "" 0x1010); err
,str name=a.Name
,if matchw(name name1)
,,out name
,out "1"
#13
Maybe does not work because your web browser control is so small. Make big and remove WS_VISIBLE style or move somewhere far.

Or maybe the web page is not completely loaded. Before foreach insert acc that finds an object in the page. Add 30 s wait time. Or instead of _s.setwintext(id(5 hDlg)) load the page using web with waiting (better in ScanName, not in Dialog3).

Macro Dialog3
Code:
Copy      Help
,case 3
,mac "ScanName" "" hDlg "http://www.quickmacros.com/forum/index.php"

Function ScanName
Code:
Copy      Help
;\
function hwnd $url
str name1 listofnames="Board index[]Untitled[]QM and Forum Info"

;start
web url 1 hwnd ;;open the url in your web browser control
;acc(... 30) ;;find an object that always exist in the page when the page is completely loaded. Wait for it max 30 s. 30 is 'waits' argument.


Acc a

foreach name1 listofnames
,a=acc(name1 "LINK" hwnd "Internet Explorer_Server" "" 0x1010); err out "'%s' not found" name1; continue
,str name=a.Name
,if matchw(name name1)
,,out name
,out "1"


Forum Jump:


Users browsing this thread: 1 Guest(s)