How can I get the text of another process’ window?

作者: admin 分类: 屏幕取词 发布时间: 2013-05-15 09:41 ė4,365 浏览数 6没有评论
文章转自王牌软件
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)

As you’ve probably found out by now, calling GetWindowText() won’t work most of the time. The reason for this is that GetWindowText() won’t do the necessary translation between the address spaces of the two processes. This is required because address that the calling process passes to GetWindowText() in the lpString parameter is not valid in the address space of the target process, so some translation is required.

However, there is one way to get around it, and that is sending a WM_GETTEXT message to the target window. Now you might be wondering how this could work, if, after all, GetWindowText() sends a WM_GETTEXT message as part of its implementation.

The answer is that Windows treats some messages differently when they are sent directly across process boundaries, and provides support for address translation (which is not a translation at all. Windows uses memory mapped files to accomplish the copy). WM_GETTEXT is one of those, as are WM_SETTEXT and WM_COPYDATA.

Keep in mind, however, that this will not work for all windows, for the simple reason that they do not store their text using WM_SETTEXT and use their own buffers for it, but don’t handle the WM_GETTEXT message appropriately.

Finally, note that GetWindowText() will work under some circumstances, namely, when the target window passes WM_SETTEXT messages to DefWindowProc(). In this case, Windows holds the window text itself in internal structures, which happens to be saved in memory shared by all processes (a memory-mapped file), so GetWindowText() will retrieve the text directly, without needing to go across process boundaries.



只回答业务咨询点击这里给我发消息 点击这里给我发消息

王牌软件,兼职软件设计,软件修改,毕业设计。

本文出自 王牌软件,转载时请注明出处及相应链接。

本文永久链接: http://www.softwareace.cn/?p=417

0

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">


Ɣ回顶部

无觅相关文章插件,快速提升流量