当前位置: 移动技术网 > IT编程>开发语言>c# > [WinApi] C#获取其他窗口文本框内容

[WinApi] C#获取其他窗口文本框内容

2020年03月09日  | 移动技术网IT编程  | 我要评论

声明部分:

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);
}

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网