同時(shí)發(fā)現了FindWindowEx只能搜索子窗口,不能搜索孫子窗口,所以,需要提前注意窗口的嵌套層次。
這個(gè)問(wèn)題完結了。我也不研究了。繼續其他的學(xué)習。
更新后的代碼
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,
延伸閱讀
文章來(lái)源于領(lǐng)測軟件測試網(wǎng) http://kjueaiud.com/