参考了vba的代码和网上的一些相关代码,想测试使用AccessibleObjectFromWindow来获取当前的Office对象,但是获取到的对象总是为空,代码如下:
[Visual Basic .NET] 纯文本查看 复制代码 Private Declare Function AccessibleObjectFromWindow Lib "oleacc" (ByVal Hwnd As Int32,
ByVal dwId As Int32,
ByRef riid As Guid,
<MarshalAs(UnmanagedType.IUnknown)> ByRef ppvObject As Object) As Int32
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim varChild As IAccessible
Dim a, b, c As IntPtr
a = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "XLMAIN", Nothing)
b = FindWindowEx(a, IntPtr.Zero, "XLDESK", Nothing)
c = FindWindowEx(b, IntPtr.Zero, "EXCEL7", Nothing)
Dim hWnd As Int32 = c.ToInt32()
Dim ID As Int32 = &HFFFFFFF0
Dim IID_IAcce As Guid = New Guid("{00020400-0000-0000-C000-000000000046}")
Dim aaVal As Int32 = AccessibleObjectFromWindow(hWnd, ID, IID_IAcce, varChild)
'这里获得的varChild总是为空,不知哪里有问题
End Sub
测试到Excel句柄获取部分都正常,
其中的Guid、ID常量均无问题。
不知该怎么修改?
|