ウィンドウハンドルを取得し、クリックボタンのメッセージを送信

1792 ワード

    [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);    //  

                }             }

}