声明部分:
const int WM_GETTEXT = 0x000D; const int WM_GETTEXTLENGTH = 0x000E; [DllImport("user32.dll", EntryPoint = "SendMessageA")] public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, Byte[] lParam); [DllImport("user32.dll", EntryPoint="SendMessageA")] public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
函数部分:
IntPtr mwh = FindMainWindowHandle("窗口名称", 100, 25); //主窗口句柄 IntPtr HwndStatue = FindWindowEx(mwh, IntPtr.Zero, "Edit", null); //文本框句柄 if (HwndStatue != IntPtr.Zero) { int TextLen; TextLen = SendMessage(HwndStatue, WM_GETTEXTLENGTH, 0, 0); Byte[] byt = new Byte[TextLen]; SendMessage(HwndStatue, WM_GETTEXT, TextLen + 1, byt); string str = Encoding.Default.GetString(byt); }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步