聲明部分: const int WM_GETTEXT = 0x000D; const int WM_GETTEXTLENGTH = 0x000E; [DllImport("user32.dll", EntryPoint = "SendMessageA")] public static extern ...
聲明部分:
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); }