Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 等待UI加载新窗口,然后继续_Vb.net_Events_Automation_Ui Automation - Fatal编程技术网

Vb.net 等待UI加载新窗口,然后继续

Vb.net 等待UI加载新窗口,然后继续,vb.net,events,automation,ui-automation,Vb.net,Events,Automation,Ui Automation,我是VB.Net的新手,尝试为一个API相当缺乏的程序创建插件。基本上,我试图完成的是按下界面上的一个按钮,这将创建一个新窗口。加载此窗口后,我需要按下其他几个按钮,以最终打印出它生成的HTML文件 我尝试使用Windows UI自动化,但无法操作第一个控件(出于某种原因,它显示为“窗格”元素,并且没有受支持的控件模式) 我最终能够使用向控件发送MouseDown和MouseUp消息来激活它 我的问题是:在继续执行代码之前,等待此窗口完成加载的最佳方式是什么 我尝试在向控件发送单击后使用Thre

我是VB.Net的新手,尝试为一个API相当缺乏的程序创建插件。基本上,我试图完成的是按下界面上的一个按钮,这将创建一个新窗口。加载此窗口后,我需要按下其他几个按钮,以最终打印出它生成的HTML文件

我尝试使用Windows UI自动化,但无法操作第一个控件(出于某种原因,它显示为“窗格”元素,并且没有受支持的控件模式)

我最终能够使用向控件发送MouseDown和MouseUp消息来激活它

我的问题是:在继续执行代码之前,等待此窗口完成加载的最佳方式是什么

我尝试在向控件发送单击后使用Thread.Sleep,但我的代码似乎在开始加载窗口之前就触发了睡眠。我怀疑可能有一些事件驱动的选项,但我甚至不知道从哪里开始

旁注:如果有帮助,我可以访问程序的进程ID

编辑:

为了更明确地说明我所做的工作,这里有一些代码供您查看:

' These variables declared further up in my program, when plugin is loaded
Private aeDesktop As AutomationElement
Private aeRadan As AutomationElement
Private aeBlocksBtn As AutomationElement

Private Sub UITest1()
Dim rpid As Integer
Dim intret As Integer

' Note: mApp is declared further up in the code, when the plug in initializes
' It sets a reference to the application object (API command from the software)

rpid = mApp.ProcessID

aeDesktop = AutomationElement.RootElement
Dim propcon As New PropertyCondition(AutomationElement.ProcessIdProperty, rpid)
Dim propcon2 As New PropertyCondition(AutomationElement.NameProperty, "big_button_blocks.bmp")

aeRadan = aeDesktop.FindFirst(TreeScope.Children, propcon)
aeBlocksBtn = aeRadan.FindFirst(TreeScope.Descendants, propcon2)

' MAKELONG is a function that concatenates given x and y coordinates into an appropriate "lparam" value for PostMessage.
' Coordinates 20, 20 are chosen arbitrarily
Dim lParam As Long = MAKELONG(20, 20)

intret = PostMessage(CInt(aeBlocksBtn.GetCurrentPropertyValue(AutomationElement.NativeWindowHandleProperty)), &H201, &H1, lParam)
intret = PostMessage(CInt(aeBlocksBtn.GetCurrentPropertyValue(AutomationElement.NativeWindowHandleProperty)), &H202, &H0, lParam)


Dim bwinprop As New PropertyCondition(AutomationElement.NameProperty, "Radan Block Editor")
Dim aeblockwin As AutomationElement
Dim numwaits As Integer = 0

Do
numwaits += 1
Thread.Sleep(100)
aeblockwin = aeRadan.FindFirst(TreeScope.Children, bwinprop)
Loop While (numwaits < 50) AndAlso (aeblockwin Is Nothing)

If numwaits >= 50 Then
MessageBox.Show("ERROR: Block Editor Window Not found")
End If
”加载插件时,这些变量在我的程序中进一步声明
作为AutomationElement的专用aeDesktop
作为自动化元件的私有aeRadan
专用aeBlocksBtn作为AutomationElement
专用子测试1()
将rpid设置为整数
作为整数的Dim intret
'注意:当插件初始化时,mApp将在代码中进一步声明
'它设置对应用程序对象的引用(来自软件的API命令)
rpid=mApp.ProcessID
aeDesktop=AutomationElement.RootElement
Dim propcon作为新属性条件(AutomationElement.ProcessIdProperty,rpid)
Dim propcon2作为新属性条件(AutomationElement.NameProperty,“big\u button\u blocks.bmp”)
aeRadan=aeDesktop.FindFirst(TreeScope.Children,propcon)
aeBlocksBtn=aeRadan.FindFirst(TreeScope.子孙,propcon2)
'MAKELONG是一个函数,它将给定的x和y坐标连接成PostMessage的适当“lparam”值。
'坐标20,20是任意选择的
Dim lParam为Long=MAKELONG(20,20)
intret=PostMessage(CInt(aeBlocksBtn.GetCurrentPropertyValue(AutomationElement.NativeWindowHandleProperty))、H201、&H1、LPRAM)
intret=PostMessage(CInt(aeBlocksBtn.GetCurrentPropertyValue(AutomationElement.NativeWindowHandleProperty))、H202、&H0、LPRAM)
Dim bwinprop作为新属性条件(AutomationElement.NameProperty,“Radan块编辑器”)
将aeblockwin设置为AutomationElement
作为整数的Dim numwaits=0
做
numwaits+=1
线程。睡眠(100)
aeblockwin=aeRadan.FindFirst(TreeScope.Children,bwinprop)
循环时(numwaits<50)和(aeblockwin不算什么)
如果numwaits>=50,则
Show(“错误:未找到块编辑器窗口”)
如果结束
我相当确信,在程序处理PostMessage之前,代码会移动到do While循环。我曾尝试使用SendMessage来绕过此问题,但不幸的是,这似乎不起作用

我觉得这里有一个非常简单的解决方案,比如我不知道的某种备用等待或睡眠命令,所以也许有人能帮我找到它

编辑2:

此控件的的屏幕截图


另外,还有一个屏幕截图。这是来自Radan,一个CAM软件,我用它来嵌套和加工要激光切割的钣金零件。我在要激活的控件周围放了一个红色框。

理想情况下,您需要包含代码,我们可以使用这些代码精确复制您的问题。读一读这个。。大卫,我更新了一些代码。我也愿意接受各种不同方法的建议。我知道中途使用UI自动化,然后再使用PostMessage,这看起来相当草率,但正如我所说,该控件不支持Cool。我希望有人能帮上忙。你能在Inspect.exe中截取控件属性的屏幕吗?可以在
C:\ProgramFiles(x86)\Windows Kits\8.1\bin\x86\inspect.exe中找到。我想看看
FrameworkId
ClassName
(也许还有更多)。瓦西里,谢谢你的评论。甚至不知道inspect.exe潜伏在那里!我以前用过Window Detective,但这个看起来更好。无论如何,用inspect输出的屏幕截图和接口的屏幕截图进行更新以供参考。理想情况下,您需要包含我们可以用来精确复制您的问题的代码。读一读这个。。大卫,我更新了一些代码。我也愿意接受各种不同方法的建议。我知道中途使用UI自动化,然后再使用PostMessage,这看起来相当草率,但正如我所说,该控件不支持Cool。我希望有人能帮上忙。你能在Inspect.exe中截取控件属性的屏幕吗?可以在
C:\ProgramFiles(x86)\Windows Kits\8.1\bin\x86\inspect.exe中找到。我想看看
FrameworkId
ClassName
(也许还有更多)。瓦西里,谢谢你的评论。甚至不知道inspect.exe潜伏在那里!我以前用过Window Detective,但这个看起来更好。无论如何,更新了inspect输出的屏幕截图和接口的屏幕截图,以供参考。