资源描述:
《多线程同步操作多个窗口》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、多线程同步操作多个窗口RunApp"notepad.exe"RunApp"notepad.exe"RunApp"notepad.exe"Delay2000Dimenvtemp_Hwndtemp_Hwnd=0Dimstr,arr,istr=Plugin.Window.Search("无标题-记事本")arr=Split(str,"
2、")Fori=0ToUBound(arr)-1temp_Hwnd=Plugin.Window.FindEx(arr(i),0,"Edit",0)BeginThreadWriteS
3、tringWhiletemp_Hwnd<>0'判断多线程已经启动完毕,继续循环下一个。Delay500WendNextEndScriptFunctionWriteString()Dimstr,HwndHwnd=temp_Hwndtemp_Hwnd=0Dostr=WaitKeyIfHwnd<>Plugin.Window.GetKeyFocusWndThenCallPlugin.Bkgnd.KeyPress(Hwnd,str)EndIfLoopEndFunction多线程多开窗口同步执行与子线程间的数值如何传
4、递:1.DimenvIsThread,i2.Dimarr_Thread()3.Fori=0To24. IsThread=False'未启动线程5. RedimPreservearr_Thread(i)6. arr_Thread(i)=BeginThread(EnterThread)7. WhileIsThread=False'未启动成功,等待中8. Delay5009. Wend10. '跳出循环说明IsThread=True,已经执行到了,循环继续启动下一个11.Next1.End
5、Script'结束主线,但子线程还会继续运行2.'函数调用//////////////////////////////////////////3.FunctionEnterThread()4. Dimn5. n=i6. IsThread=True7. Do8. TracePrint"运行线程:"&n9. Delay50010. Loop11.EndFunction多线程运行中单独停止某个子线程演示:1.'环境变量声明2.DimenvHwnd,IsThread3.IsThrea
6、d=False4.Do5. Hwnd=Plugin.Window.Find("Notepad","无标题-记事本")6. IfHwnd=0Then7. RunApp"notepad.exe":Delay20008. TracePrint"运行记事本"9. EndIf10.LoopWhileHwnd=011.'获得记事本中输入子窗口句柄,以便按键输入内容12.Hwnd=Plugin.Window.FindEx(Hwnd,0,"Edit",0)13.'全局变量声明14.DimIdTh
7、read15.'主循环↓16.Do17. IfWaitKey()=81Then18. IfIsThread=FalseThen 19. IdThread=BeginThread(WriteString)20. Do21. TracePrint"等待线程启动!"1. Delay5002. LoopWhileIsThread=False3. TracePrint"线程启动成功!"4. Else5.
8、 TracePrint"线程停止操作!"6. StopThreadIdThread7. IsThread=False8. EndIf9. EndIf10.Loop11.'以下是函数区域↓12.FunctionWriteString()13. IsThread=True14. Do15. CallPlugin.Bkgnd.KeyPress(Hwnd,65)16. Delay50017. Loop18.EndFunction主线程
9、逐个开启子线程五开操作演示:1.'五开操作2.Dimstr_Hwnd3.str_Hwnd=vbNullString'记录都有哪些窗口句柄在运行4.DimEnvIsHwnd5.IsHwnd=06.Fori_win=0To47. Do8. RunApp"notepad.exe"9. str=Plugin.Window.Search("无标题-记事本")10. arr=Split(str,"
10、")11