VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > 简明python教程 >
  • [WinApi] C#获取其他窗口文本框内容

声明部分:

复制代码
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);
}
复制代码


相关教程