同时发现了FindWindowEx只能搜索子窗口,不能搜索孙子窗口,所以,需要提前注意窗口的嵌套层次。
这个问题完结了。我也不研究了。继续其他的学习。
更新后的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Runtime.InteropServices;
using Accessibility;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int hWnd = FindWindowEx(0, 0, "Maxthon2_Frame", null);
int sub = FindWindowEx(hWnd, 0, "XTPDockBar", null);
int subhwnd = FindWindowEx(sub, 0, null, "标准工具栏");
if (subhwnd!= null)
Console.WriteLine("OK, Found the toolbar");
msaa((IntPtr)subhwnd);
Console.ReadKey();
}
[DllImport("oleacc", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int AccessibleChildren(IAccessible paccContainer, int iChildStart, int cChildren, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] object[] rgvarChildren, ref int pcObtained);
[DllImport("oleacc.dll")]
internal static extern int AccessibleObjectFromWindow(
IntPtr hwnd,
uint id,
ref Guid iid,
[In, Out, MarshalAs(UnmanagedType.IUnknown)] ref object ppvObject);
internal enum OBJID : uint
{
WINDOW = 0x00000000,
SYSMENU = 0xFFFFFFFF,
TITLEBAR = 0xFFFFFFFE,
MENU = 0xFFFFFFFD,
CLIENT = 0xFFFFFFFC,
VSCROLL = 0xFFFFFFFB,
HSCROLL = 0xFFFFFFFA,
SIZEGRIP = 0xFFFFFFF9,
CARET = 0xFFFFFFF8,
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/