zjsong 发表于 2014-9-2 11:48:55

在vba中调用autoit的问题

本帖最后由 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?

zjsong 发表于 2014-9-2 17:35:32

一点线索:那个h的变量类型是字符串,但autoit要求是指针类型,所以问题是:如何把h转为指针?

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

ph = VarPtr(h)


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

Set au3 = Nothing

End Sub

autoit:
;Run("notepad.exe")

$w=""
WinActivate($w)
$h=ControlGetHandle($w,"","Edit1")
ControlSetText($w,"",$h,"12345")
MsgBox(0,0,$h & " " & VarGetType($h))

kevinch 发表于 2014-9-3 11:46:52

调用au3里的ptr或者hwnd把字符串转换一下试试

cihren 发表于 2014-9-11 00:38:01

貌似很高深,呵呵!
页: [1]
查看完整版本: 在vba中调用autoit的问题