根据http://msdn.microsoft.com/en-us/library/ms633500(v=vs.85).aspx我定义了FindWindowEx函数.
using System.Runtime.InteropServices;
[DllImport("user32.dll", CharSet=CharSet.Unicode)]
static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);
Run Code Online (Sandbox Code Playgroud)
现在我能够找到第一个 "Button"控件的句柄(从Spy ++获取名称),将childAfter设置为IntPtr.Zero.
IntPtr hWndParent = new IntPtr(2032496); // providing parent window handle
IntPtr hWndButton = FindWindowEx(hWndParent, IntPtr.Zero, "Button", string.Empty);
Run Code Online (Sandbox Code Playgroud)
如何在父窗口中获取"Button"控件的第二个,第三个或任何句柄?事实是,按钮标题可能会有所不同,所以我无法通过名称定义第四个参数直接找到它们.