1 Star 0 Fork 0

yongzhi / w32uiautomation

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
waitfind.go 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
package w32uiautomation
import (
"syscall"
"unsafe"
"github.com/go-ole/go-ole"
)
func WaitFindFirst(auto *IUIAutomation, elem *IUIAutomationElement, scope TreeScope, condition *IUIAutomationCondition) (found *IUIAutomationElement, err error) {
for {
found, err = elem.FindFirst(scope, condition)
if err != nil {
return nil, err
}
if found != nil {
return found, nil
}
waitChildAdded(auto, elem)
}
}
func waitChildAdded(auto *IUIAutomation, elem *IUIAutomationElement) error {
waiting := true
handler := NewStructureChangedEventHandler(nil)
lpVtbl := (*IUIAutomationStructureChangedEventHandlerVtbl)(unsafe.Pointer(handler.IUnknown.RawVTable))
lpVtbl.HandleStructureChangedEvent = syscall.NewCallback(func(this *IUIAutomationStructureChangedEventHandler, sender *IUIAutomationElement, changeType StructureChangeType, runtimeId *ole.SAFEARRAY) syscall.Handle {
switch changeType {
case StructureChangeType_ChildAdded, StructureChangeType_ChildrenBulkAdded:
waiting = false
}
return ole.S_OK
})
err := auto.AddStructureChangedEventHandler(elem, TreeScope_Subtree, nil, &handler)
if err != nil {
return err
}
var m ole.Msg
for waiting {
ole.GetMessage(&m, 0, 0, 0)
ole.DispatchMessage(&m)
}
err = auto.RemoveStructureChangedEventHandler(elem, &handler)
if err != nil {
return err
}
return nil
}
Go
1
https://gitee.com/yongzhi4/w32uiautomation.git
git@gitee.com:yongzhi4/w32uiautomation.git
yongzhi4
w32uiautomation
w32uiautomation
23a1f2281c99

搜索帮助

53164aa7 5694891 3bd8fe86 5694891