Exemplo n.º 1
0
        private void btnAddUser_Click(object sender, EventArgs e)
        {
            IntPtr wndFx = FindWindow(null, this.txtWindowName.Text);

            if (wndFx == null)
            {
                MessageBox.Show("飞信2013窗口未找到");
                return;
            }

            Rectangle rc = new Rectangle();

            GetWindowRect(wndFx.ToInt32(), ref rc);
            SetCursorPos(rc.X + 140, rc.Y + 468); //设置鼠标位置

            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

            Thread.Sleep(500);


            IntPtr wndAddUser = FindWindow(null, "添加好友");

            if (wndAddUser != null)
            {
                Rectangle rcAddUser = new Rectangle();
                GetWindowRect(wndAddUser.ToInt32(), ref rcAddUser);

                //寻找好友句柄
                List <IntPtr> list = new List <IntPtr>();
                WinAPIuser32.CallFuntion = delegate(IntPtr enumIntPtr)
                {
                    StringBuilder s = new StringBuilder(2000);
                    WinAPIuser32.GetClassName(enumIntPtr, s, 255);
                    if (s.ToString() == "FxEdit")
                    {
                        list.Add(enumIntPtr);
                    }
                };
                WinAPIuser32.EnumChildWindows(wndAddUser, 0);
                WinAPIuser32.CallFuntion = null;

                //设置好友
                Console.WriteLine("lst count:" + list.Count);
                WinAPIuser32.SendTextMessage(list[3], WM_SETTEXT, 0, txtUserCode.Text);

                //移动到发送按钮,并点击
                SetCursorPos(rcAddUser.X + 430, rcAddUser.Y + 100);
                mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

                Thread.Sleep(500);

                //寻找显示名称,申请理由句柄
                list = new List <IntPtr>();
                WinAPIuser32.CallFuntion = delegate(IntPtr enumIntPtr)
                {
                    StringBuilder s = new StringBuilder(2000);
                    WinAPIuser32.GetClassName(enumIntPtr, s, 255);
                    if (s.ToString() == "FxEdit")
                    {
                        list.Add(enumIntPtr);
                    }
                };
                WinAPIuser32.EnumChildWindows(wndAddUser, 0);
                WinAPIuser32.CallFuntion = null;

                WinAPIuser32.SendTextMessage(list[4], WM_SETTEXT, 0, txtUserCode.Text);
                WinAPIuser32.SendTextMessage(list[5], WM_SETTEXT, 0, string.Format("欢迎使用淘快词,请加为好友,否则将不能收到短信通知"));

                //Thread.Sleep(500);
                ////模拟回车
                ////移动到确定按钮,并点击
                //SetCursorPos(rcAddUser.X + 390, rcAddUser.Y + 318);
                //mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                //mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

                //Thread.Sleep(4000);
                ////移动到关闭按钮,并点击
                //SetCursorPos(rcAddUser.X + 490, rcAddUser.Y + 10);
                //mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                //mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
            }
        }
Exemplo n.º 2
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            IntPtr wndFx = FindWindow(null, this.txtWindowName.Text);

            if (wndFx == null)
            {
                MessageBox.Show(string.Format("{0}窗口未找到", this.txtWindowName.Text));
                return;
            }

            Rectangle rc = new Rectangle();

            GetWindowRect(wndFx.ToInt32(), ref rc);

            //移动到好友搜索栏,并点击
            SetCursorPos(rc.X + 50, rc.Y + 150);
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

            //寻找查找好友,群和宝贝句柄
            List <IntPtr> list = new List <IntPtr>();

            WinAPIuser32.CallFuntion = delegate(IntPtr enumIntPtr)
            {
                StringBuilder s = new StringBuilder(2000);
                WinAPIuser32.GetClassName(enumIntPtr, s, 255);
                if (s.ToString() == "EditComponent")
                {
                    list.Add(enumIntPtr);
                }
            };
            WinAPIuser32.EnumChildWindows(wndFx, 0);
            WinAPIuser32.CallFuntion = null;

            //设置好友名称
            Console.WriteLine("lst count:" + list.Count());
            WinAPIuser32.SendTextMessage(list[1], WM_SETTEXT, 0, txtUserName.Text);

            Thread.Sleep(500);

            //模拟回车
            PostMessage(list[1], WM_KEYDOWN, 13, 0);


            Thread.Sleep(500);

            //寻找聊天窗口
            IntPtr wndSendMsg = FindWindow(null, string.Format("{0} - {1}", txtUserName.Text, txtSendUser.Text));


            //寻找信息编辑框
            List <IntPtr> listRichEditComponent = new List <IntPtr>();

            WinAPIuser32.CallFuntion = delegate(IntPtr enumIntPtr)
            {
                StringBuilder s = new StringBuilder(2000);
                WinAPIuser32.GetClassName(enumIntPtr, s, 255);
                if (s.ToString() == "RichEditComponent")
                {
                    listRichEditComponent.Add(enumIntPtr);
                }
            };
            WinAPIuser32.EnumChildWindows(wndSendMsg, 0);
            WinAPIuser32.CallFuntion = null;

            //输入信息内容
            Console.WriteLine("listRichEditComponent count:" + listRichEditComponent.Count());
            WinAPIuser32.SendTextMessage(listRichEditComponent[0], WM_SETTEXT, 0, txtMsg.Text);

            Thread.Sleep(500);

            //寻找发送按钮
            Rectangle rcSendMsg = new Rectangle();

            GetWindowRect(wndSendMsg.ToInt32(), ref rcSendMsg);

            //移动到发送按钮,并点击
            SetCursorPos(rcSendMsg.X + 300, rcSendMsg.Y + 488);
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);


            Thread.Sleep(500);
            //移动到关闭按钮,并点击
            SetCursorPos(rcSendMsg.X + 544, rcSendMsg.Y + 14);
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
        }
Exemplo n.º 3
0
        private void btnSendOneMsg_Click(object sender, EventArgs e)
        {
            MsgCount++;
            logger.InfoFormat("第{0}条开始发送", MsgCount);
            IntPtr wndFx = FindWindow(null, this.txtWindowName.Text);

            if (wndFx == null)
            {
                MessageBox.Show("飞信2013窗口未找到");
                return;
            }

            Rectangle rc = new Rectangle();

            GetWindowRect(wndFx.ToInt32(), ref rc);

            //移动到短信按钮,并点击
            SetCursorPos(rc.X + 69, rc.Y + 438);
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

            Thread.Sleep(500);

            IntPtr wndSendMsg = FindWindow(null, "发短信");

            if (wndSendMsg != null)
            {
                Rectangle rcSendMsg = new Rectangle();
                GetWindowRect(wndSendMsg.ToInt32(), ref rcSendMsg);

                //移动到接收人,并设置光标
                SetCursorPos(rcSendMsg.X + 100, rcSendMsg.Y + 42); //设置鼠标位置
                mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

                Thread.Sleep(500);

                //寻找接收人和短信内容句柄
                List <IntPtr> list = new List <IntPtr>();
                WinAPIuser32.CallFuntion = delegate(IntPtr enumIntPtr)
                {
                    StringBuilder s = new StringBuilder(2000);
                    WinAPIuser32.GetClassName(enumIntPtr, s, 255);
                    if (s.ToString() == "FxRichEdit")
                    {
                        list.Add(enumIntPtr);
                    }
                };
                WinAPIuser32.EnumChildWindows(wndSendMsg, 0);
                WinAPIuser32.CallFuntion = null;

                //设置接收人
                Console.WriteLine("lst count:" + list.Count);
                WinAPIuser32.SendTextMessage(list[0], WM_SETTEXT, 0, txtUserCode.Text);

                Thread.Sleep(500);
                //模拟回车
                PostMessage(list[0], WM_KEYDOWN, 13, 0);

                //设置短信内容
                Thread.Sleep(500);
                WinAPIuser32.SendTextMessage(list[2], WM_SETTEXT, 0, txtMsg.Text);


                //移动到发送按钮,并点击
                SetCursorPos(rcSendMsg.X + 340, rcSendMsg.Y + 210);
                mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

                Thread.Sleep(4000);
                //移动到关闭按钮,并点击
                SetCursorPos(rcSendMsg.X + 380, rcSendMsg.Y + 16);
                mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
            }

            logger.InfoFormat("第{0}条完成发送", MsgCount);
            btnSendOneMsg.Enabled = true;
        }