电竞比分网-中国电竞赛事及体育赛事平台

分享

[WinApi] C#獲取其他窗口文本框內(nèi)容

 小樣樣樣樣樣樣 2021-04-12

聲明部分:

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

 

函數(shù)部分:

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

 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多