获取其他句柄文本框信息

以下仅为举例,具体获取句柄可用自带 Spy++工具找

        [DllImport("user32.dll")]
        private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll")]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
        [DllImport("user32.dll", EntryPoint = "SendMessageA")]
        private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, StringBuilder lParam);

        const int WM_GETTEXT = 0x0D;
        const int buffer_size = 1024 * 10;
        IntPtr myp = IntPtr.Zero;

        myp = FindWindow(null, "通用考试平台");

        StringBuilder QuestionBuffer = new StringBuilder(buffer_size);

        IntPtr my0 = new IntPtr(0);
        IntPtr my1 = new IntPtr(0);
        IntPtr my2 = new IntPtr(0);
        IntPtr my3 = new IntPtr(0);
        IntPtr my4 = new IntPtr(0);

        my0 = FindWindowEx(myp, IntPtr.Zero, null, null);
        my1 = FindWindowEx(my0, IntPtr.Zero, null, null);
        my2 = FindWindowEx(my1, IntPtr.Zero, null, null);
        my3 = FindWindowEx(my2, IntPtr.Zero, null, null);
        my4 = FindWindowEx(my2, my3, "RichTextWndClass", null);

        SendMessage(my4, WM_GETTEXT, buffer_size, QuestionBuffer);
        string temp = QuestionBuffer.ToString();

鼠标控制

比如调用 this.AutoClick(int.Parse(textBox1.Text), int.Parse(textBox2.Text));即可

  • 如果软件有检测,以下方法可能失效。
        ////////////////////////////////
        // 鼠标事件代码
        [DllImport("User32")]
        public extern static void mouse_event(int dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo);

        [DllImport("User32")]
        public extern static void SetCursorPos(int x, int y);

        [DllImport("User32")]
        public extern static bool GetCursorPos(out POINT p);

        [StructLayout(LayoutKind.Sequential)]
        public struct POINT
        {
            public int X;
            public int Y;
        }

        public enum MouseEventFlags
        {
            Move = 0x0001,
            LeftDown = 0x0002,
            LeftUp = 0x0004,
            RightDown = 0x0008,
            RightUp = 0x0010,
            MiddleDown = 0x0020,
            MiddleUp = 0x0040,
            Wheel = 0x0800,
            Absolute = 0x8000
        }

        private void AutoClick(int x, int y)
        {
            POINT p = new POINT();
            GetCursorPos(out p);
            try
            {
                SetCursorPos(x, y);
                mouse_event((int)(MouseEventFlags.LeftDown | MouseEventFlags.Absolute), 0, 0, 0, IntPtr.Zero);
                mouse_event((int)(MouseEventFlags.LeftUp | MouseEventFlags.Absolute), 0, 0, 0, IntPtr.Zero);
            }
            finally
            {
                SetCursorPos(p.X, p.Y);
            }
        }

        ////////////////////////////////

获取鼠标当前位置

        private void timer1_Tick(object sender, EventArgs e)
        {
            textBox14.Text = Cursor.Position.X.ToString();
            textBox13.Text = Cursor.Position.Y.ToString();
        }



扫一扫在手机打开当前页