[DllImport("User32.dll ")] public static extern System.IntPtr FindWindowEx(System.IntPtr parent, System.IntPtr childe, string strclass, string strname); [DllImport("user32.dll", EntryPoint = "SendMessageA")] private static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);//MsiDialogCloseClass是使用spy++获取的类名,eFax是窗体名称,Convert.ToString(childHwnd.ToInt64(), 16);将10进制句柄转为16进制表示方式
static void Main(string[] args)
{IntPtr p = System.IntPtr.Zero; p = FindWindowEx(System.IntPtr.Zero, System.IntPtr.Zero, "MsiDialogCloseClass", "eFax"); Debug.WriteLine("Try count:" + count + ":and the handle value of p is==>" + p);
if (p != IntPtr.Zero) { IntPtr childHwnd = FindWindowEx(p, IntPtr.Zero, "Button", "&Next >"); //获得按钮的句柄
Convert.ToString(childHwnd.ToInt64(), 16); //Console.ReadKey(); if (childHwnd != IntPtr.Zero) { //000809,为什么SendMessage两次才有效果,还不清楚。 int i = SendMessage(childHwnd, 0xF5, System.IntPtr.Zero, System.IntPtr.Zero); do { i = SendMessage(childHwnd, 0xF5, System.IntPtr.Zero, System.IntPtr.Zero); } while (i != 0); //SendMessage(childHwnd, 0xF5, System.IntPtr.Zero, System.IntPtr.Zero); //发送点击按钮的消息
} }
}