从网上搜索到一段代码。我使用它来验证我的一个思想。
spy++肯定是根据hwnd来遍历的。如果一个控件不能被spy++识别。就只能通过msaa来识别。
这样是说hwnd和msaa并不是一一对应。疑问?
这个代码是无法遍历到遨游的工具栏的。
我使用msaa是可以的。
同时也可以使用消息,通过spy++获取发送的消息,然后模拟就可以了。
鼠标点击的位置是可以通过他们的父控件的位置来计算出来的。
再想,也许可以有
其他的方法。
static void Main(string[] args)
{
//IsClientPopupWindows();
EnumChildWindows(920262, callBackEnumChildWindows, 0);
Console.ReadKey();
}
[DllImport("user32.dll")]
public static extern int FindWindowEx(int hwndParent, int hwndChildAfter,
string lpszClass, string lpszWindow);
[DllImport("user32.dll")]
public static extern int FindWindow(string strclassName, string strWindowName);
[DllImport("user32.dll")]
public static extern int GetLastActivePopup(int hWnd);
[DllImport("user32.dll")]
public static extern int AnyPopup();
[DllImport("user32.dll")]
public static extern int GetWindowText(int hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
public static extern int EnumThreadWindows(int dwThreadId, CallBack lpfn, int lParam);
[DllImport("user32.dll")]
public static extern int EnumWindows(CallBack lpfn, int lParam);
[DllImport("user32.dll")]
public static extern int EnumChildWindows(int hWndParent, CallBack lpfn, int lParam);
/// <summary>
/// 回调函数代理
/// </summary>
public delegate bool CallBack(int hwnd, int lParam);
/// <summary>
/// 进程回调处理函数
/// </summary>
/// <param name="hwnd"></param>
/// <param name="lParam"></param>
/// <returns></returns>
public static bool ThreadWindowProcess(int hwnd, int lParam)
{
EnumChildWindows(hwnd, callBackEnumChildWindows, 0);
return true;
}
/// <summary>
/// 窗口回调处理函数
/// </summary>
/// <param name="hwnd"></param>
/// <param name="lParam"></param>
/// <returns></returns>
public static bool WindowProcess(int hwnd, int lParam)
{
EnumChildWindows(hwnd, callBackEnumChildWindows, 0);
return true;
}
/// <summary>
/// 子窗口回调处理函数
/// </summary>
/// <param name="hwnd"></param>
/// <param name="lParam"></param>
/// <returns></returns>
public static bool ChildWindowProcess(int hwnd, int lParam)
{
StringBuilder title = new StringBuilder(200);
int len;
len = GetWindowText(hwnd, title, 200);
if (len < 1)
return true;
if(title.ToString().Contains("标准工具栏"))
EnumChildWindows(hwnd, callBackEnumChildWindows, 0);
Console.WriteLine(title+" "+hwnd);
return true;
}
/// <summary>
/// 进程窗口回调函数代理
/// </summary>
public static CallBack callBackEnumThreadWindows = new CallBack(ThreadWindowProcess);
/// <summary>
/// 窗口回调函数代理
/// </summary>
public static CallBack callBackEnumWindows = new CallBack(WindowProcess);
/// <summary>
/// 子窗口回调函数代理
/// </summary>
public static CallBack callBackEnumChildWindows = new CallBack(ChildWindowProcess);
/// <summary>
/// 客户端是否弹出对话框
/// </summary>
/// <returns></returns>
public static bool IsClientPopupWindows()
{
bool FindError = false;
EnumWindows(callBackEnumWindows, 0);
return FindError;
}