Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Immediate window appearance check
#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.


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)