C#怎样获取其它窗口的内容?

hxhyxd 2010-02-05 02:42:38
string lpszParentWindow = "事情.txt - 记事本"; //主窗口标题
string lpszParentClass = "Notepad"; //主窗口类名
string lpszClass = "Edit"; //子窗口类名
IntPtr ParenthWnd = new IntPtr(0);
IntPtr EdithWnd = new IntPtr(0);
ParenthWnd = Api.FindWindow("Notepad", lpszParentWindow);
if(!ParenthWnd.Equals(IntPtr.Zero))
{
Api.SetForegroundWindow(ParenthWnd);
EdithWnd = Api.FindWindowEx(ParenthWnd, EdithWnd, lpszClass,"");
Api.WaitTime(1000);
StringBuilder s = new StringBuilder(512);
int i = Api.GetWindowText(EdithWnd, s, s.Capacity);
MessageBox.Show(s.ToString());
}

为什么弹出的消息为空的呢?我的记事本中有内容的
...全文
212 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hxhyxd 2010-02-05
  • 打赏
  • 举报
回复
问题解决了
CsToD 2010-02-05
  • 打赏
  • 举报
回复
自己去查GetWindowText,该函数不能获取“其它进程”的“子”窗口文本

使用SendMessage (WM_GETTEXT)代替
graint1 2010-02-05
  • 打赏
  • 举报
回复
深奥。。路过。。学习。。帮顶
hxhyxd 2010-02-05
  • 打赏
  • 举报
回复
怎样通过窗口句柄获得窗口内容?

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧