C#得到其他窗体的文字

   [DllImport("user32.dll", EntryPoint = "FindWindow")]
        private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
        private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);


   [DllImport("user32.dll", SetLastError = true)]
        public static extern int SendMessage(IntPtr hWnd, int msg, int Param, System.Text.StringBuilder text);
        const int WM_GETTEXT = 0x000D;

 

private void ReadData_Btn_Click(object sender, EventArgs e)
        {
            IntPtr hPwnd = new IntPtr(0);
            IntPtr C1wnd = new IntPtr(0);
            hPwnd = FindWindow(null, DataWnd_TextBox.Text);

            if (hPwnd != IntPtr.Zero)
            {
                C1wnd = FindChildWindowID(hPwnd, 3);
                SendMessage(C1wnd, WM_GETTEXT, sb.Capacity, sb);
                LeftLine_textBox.Text = sb.ToString();
            }
            else
            {
                toolStripStatusLabel2.Text = "没有找到测量窗口";
            }

}

posted @ 2019-07-28 11:01  lxdawn  阅读(643)  评论(0)    收藏  举报