多线程同步操作多个窗口 RunApp "notepad.exe" RunApp "notepad.exe" RunApp "notepad.exe" Delay 2000 Dimenv temp_Hwnd temp_Hwnd = 0 Dim str, arr, i str = Plugin.Window.Search("无标题 - 记事本") arr = Split(str, "|") For i = 0 To UBound(arr) - 1 temp_Hwnd = Plugin.Window.FindEx(arr(i), 0, "Edit", 0) BeginThread WriteString While temp_Hwnd <> 0'判断多线程已经启动完毕,继续循环下一个。 Delay 500 Wend Next EndScript Function WriteString() Dim str, Hwnd Hwnd = temp_Hwnd temp_Hwnd = 0 Do str = WaitKey If Hwnd <> Plugin.Window.GetKeyFocusWnd Then Call Plugin.Bkgnd.KeyPress(Hwnd, str) End If Loop End Function 多线程多开窗口同步执行与子线程间的数值如何传递: 1. Dimenv IsThread, i 2. Dim arr_Thread() 3. For i = 0 To 2 4. IsThread = False'未启动线程 5. Redim Preserve arr_Thread(i) 6. arr_Thread(i) = BeginThread(EnterThread) 7. While IsThread = False'未启动成功,等待中 8. Delay 500 9. Wend 10. '跳出循环说明 IsThread = True,已经执行到了,循环继续启动下一个 11. Next 12. EndScript'结束主线,但子线程还会继续运行 13. '函数调用////////////////////////////////////////// 14. Function EnterThread() 15. Dim n 16. n = i 17. IsThread = True 18. Do 19. TracePrint "运行线程:" & n 20. Delay 500 21. Loop 22. End Function 多线程运行中单独停止某个子线程演示: 1. '环境变量声明 2. Dimenv Hwnd, IsThread 3. IsThread = False 4. Do 5. Hwnd = Plugin.Window.Find("Notepad", "无标题 - 记事本") 6. If Hwnd = 0 Then 7. RunApp "notepad.exe" : Delay 2000 8. TracePrint "运行记事本" 9. End If 10. Loop While Hwnd = 0 11. '获得记事本中输入子窗口句柄,以便按键输入内容 12. Hwnd = Plugin.Window.FindEx(Hwnd, 0, "Edit", 0) 13. '全局变量声明 14. Dim IdThread 15. '主循环↓ 16. Do 17. If WaitKey() = 81 Then 18. If IsThread = False Then 19. IdThread = BeginThread(WriteString) 20. Do 21. T...