Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Immediate window appearance check
#1
Hey, i need some advice about how to check window appearance. For example if i make something like this:

Code:
Copy      Help
rep
  ifi win("somewindow")
    ;;do something
  else
    ;;do something else and long enough
the problem is if "somewindow" appears during <else> part it breaks logic. Perhaps i need to run some check in another thread but im noobie with it. Need such thing in EXE also.

So it should be like:
do something else and long enough
when "somewindow" appears stop it and do more code
when "somewindow" disappears continue it

Also would be nice (if any important) to make it work with any event not only with win.
#2
In this example other thread waits for Notepad window and then temporarily suspends main macro.

Macro Macro2325
Code:
Copy      Help
;start thread that waits for a window or something and then temporarily suspends this thread
QMTHREAD qt; GetQmThreadInfo(0 &qt)
mac "thread_wait_window" "" qt.threadhandle

;main macro code example
int i
for i 0 1000
,1
,out i

Function thread_wait_window
Code:
Copy      Help
;\
function mainThreadHandle

atend ResumeThread mainThreadHandle
rep
,;wait for some condition, eg window created and visible
,rep
,,0.01
,,if(WaitForSingleObject(mainThreadHandle 0)!=WAIT_TIMEOUT) ret ;;macro ended
,,int w=win("Notepad" "Notepad" "" 0x400) ;;check the condition (edit this line)
,,if(w) break
,
,;suspend main thread
,SuspendThread(mainThreadHandle)
,
,;do something with the window (replace this code with your code)
,sel mes("Now macro is suspended.[][]OK - close window and resume macro.[]Cancel - end macro." "" "OC")
,,case 'O'
,,clo w; err
,,0.1
,,
,,case else
,,EndThread "" mainThreadHandle
,,ret
,
,;resume main thread
,ResumeThread(mainThreadHandle)

SuspendThread can be dangerous, the two threads can lock each other. It depends on what code is executed in main thread and what code is executed in other thread while main thread is suspended. But this is the easiest solution. Else main thread would have to periodically check if it should wait.
#3
Thanks


Forum Jump:


Users browsing this thread: 1 Guest(s)