找回密码
 加入
搜索
查看: 3485|回复: 6

[系统综合] 在vba中调用autoit的问题

[复制链接]
发表于 2014-9-2 11:48:55 | 显示全部楼层 |阅读模式
本帖最后由 zjsong 于 2014-9-2 11:51 编辑

需要 在vba中调用autoit,下面是vba 代码:
Sub t()

Set au3 = CreateObject("autoitx3.control")

w = "无标题 - 记事本"
au3.WinActivate (w)

Call au3.ControlSetText(w, "", "Edit1", "123") 'OK

h = au3.ControlGetHandle(w, "", "Edit1")
Call au3.ControlSetText(w, "", h, "12345") 'Fail

'MsgBox h

Set au3 = Nothing

End Sub
为什么vba不能将句柄h正确传给autoit?
 楼主| 发表于 2014-9-2 17:35:32 | 显示全部楼层
一点线索:那个h的变量类型是字符串,但autoit要求是指针类型,所以问题是:如何把h转为指针?

vba:
Sub t()

Set au3 = CreateObject("autoitx3.control")

w = "[CLASS:Notepad]"
au3.WinActivate (w)

Call au3.ControlSetText(w, "", "Edit1", "123") 'OK

h = au3.ControlGetHandle(w, "", "Edit1")
Call au3.ControlSetText(w, "", h, "12345") 'Fail

ph = VarPtr(h)


MsgBox TypeName(h) & " " & TypeName(ph)

Set au3 = Nothing

End Sub
autoit:
;Run("notepad.exe")

$w="[CLASS:Notepad]"
WinActivate($w)
$h=ControlGetHandle($w,"","Edit1")
ControlSetText($w,"",$h,"12345")
MsgBox(0,0,$h & " " & VarGetType($h))
发表于 2014-9-3 11:46:52 | 显示全部楼层
调用au3里的ptr或者hwnd把字符串转换一下试试
发表于 2014-9-11 00:38:01 | 显示全部楼层
貌似很高深,呵呵!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-20 15:13 , Processed in 0.079415 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表