找回密码
 加入
搜索
查看: 19161|回复: 16

[系统综合] 请教这个dll的使用:屏幕取文字的应用

 火.. [复制链接]
发表于 2011-3-18 13:47:43 | 显示全部楼层 |阅读模式
悬赏500金钱已解决
本帖最后由 tryhi 于 2011-3-20 00:16 编辑

发悬赏贴只在于表示诚信请教,高手都是不在乎金币的,这我知道。
我想用AU3实现这样一个功能,在屏幕选择一定区域,然后获取这个区域的文字(图片上的文字不在考虑范围内),就像Aqua Deskperience一样
Aqua Deskperience软件提供了一个可以提取文字的DLL,并有详细说明,我做了个不完全的翻译(英语太烂了),请问下AU3怎样调用呢。

1.  描述

TcaptureX库允许文本提取的
各种应用。它包含了一个COM对象来调用
TextCaptureX,暴露的一些方法,让文本
提取。

1.1.     创建一个TextCaptureX对象
首先,TcaptureX库必须注册
该系统。使用下列命令进行注册
:

regsvr32 <路径>\TCaptureX.dll

TCaptureX注册过程是自动完成安装.

下面是一些例子关于如何创建一TextCaptureX对象在你的应用程序.

1.1.1.                 Visual C++:
In   order   to   use   the   COM   object   in   your   C++
application, add the following import statement to your C++
source file, like this:

#import "<path>\TCaptureX.dll"

Optionally, you may add also:

using namespace TCaptureXLib;
in order to reference
the namespace.
the objects without specifying
Then  create  the  object  in  one  of  the  following  two
ways:
ITextCaptureXPtr obj(__uuidof(TextCaptureX));
Or
ITextCaptureXPtr obj = NULL;
HRESULT hr = obj.CreateInstance(__uuidof(TextCaptureX));
In order to destroy the object, call:

obj.Release();


备注:  创建对象,CoInitialize之前必须首先调用API函数.
1.1.2.
C#
-
add  TCaptureX  library  to  the  list  of  the  project
references
Optionally, you may add at the beginning of the file:

using TCaptureXLib;
in order to reference
the namespace.

The actual creation is:
the objects without specifying
TextCaptureXClass obj = new TextCaptureXClass();
1.1.3.
Visual Basic
-
add  TCaptureX  library  to  the  list  of  the  project
references
The actual creation is:

Dim obj As New TextCaptureX
1.2.
使用一个TextCaptureX对象
TextCaptureX object exposes the following methods:
-
-
-
-
-
GetActiveWindowHwnd
CaptureInteractive
CaptureActiveWindow
GetTextFromPoint
GetTextFromRect
1.2.1.
GetActiveWindowHwnd method
HRESULT GetActiveWindowHwnd([out,retval] LONG* hwnd);

它的作用是:返回当前窗口的句柄。如果当前窗口是一个MDI容器,它返回的柄活跃的MDI的孩子.

例子:


Visual C++:
LONG hWnd = obj->GetActiveWindowHwnd();
C#:
long hWnd = obj.GetActiveWindowHwnd();
Visual Basic:

Dim hWnd As Long
hWnd = obj.GetActiveWindowHwnd()
1.2.2.
CaptureInteractive method
HRESULT  CaptureInteractive([out]  LONG*  hwnd,  [out]  LONG*  left,
[out]   LONG*   top,   [out]   LONG*   width,   [out]   LONG*   height,
[out,retval] LONG* selection);
这个方法允许被自动选择捕获窗口和坐标。当调用这个方法,用户可以选择一个矩形用鼠标在屏幕上,不管遇到什么样的窗口。在第一个路口左拐点击指定的地方开始,第二次矩形左键点击指定的地方选择结束。在任何时候,按ESC键,中止的选择。

Parameters:
LONG* hwnd : 将包含的窗口句柄
LONG* left: X坐标的选择矩形
LONG* top: Y坐标选定矩形
LONG* width: 所选择的矩形的宽度
LONG* height: 所选择的矩形的宽度
LONG* selection: 自定义值,指定捕捉结果:
-
-
-
0  , 如果选择是确定
1  , 如果用户取消了捕捉
2  , 如果发生错误
Examples:
Visual C++:

long hWnd = 0;
long nLeft = 0;
long nTop = 0;
long nWidth = 0;
long nHeight = 0;
LONG  result  =  obj->CaptureInteractive(&hWndTarget,  &nLeft,
&nTop, &nWidth, &nHeight);
if(0 == result) //selection ok
{

}
//do something


C#:
long hWnd = 0;
long nLeft = 0;
long nTop = 0;
long nWidth = 0;
long nHeight = 0;
long  result  =  obj.CaptureInteractive(out  hWndTarget,  out
nLeft, out nTop, out nWidth, out nHeight);
if(0 == result) //selection ok
{

}
//do something
Visual Basic:
Dim result As Long
Dim hWnd As Long
Dim left As Long
Dim top As Long
Dim width As Long
Dim height As Long
result  =  obj.CaptureInteractive(hWnd,  left,  top,  width,
height)
If(0 == result) Then 'selection ok
{

}
End If
'do something
1.2.3.
CaptureActiveWindow method
HRESULT CaptureActiveWindow([out,retval] BSTR* result);

这种方法捕获从当前活动窗口中的文本,
是由GetActiveWindowHwnd方法返回的窗口。该
返回值是从当前窗口中的整个文本。
注:如果这种方法被称为应用程序是负责任的
不包含该系统的活动窗口。

参数:
BSTR* result : 从活动窗口中的文字

例子:
Visual C++:

_bstr_t result = obj->CaptureActiveWindow();
C#:
string result = obj.CaptureActiveWindow();
Visual Basic:
Dim result As String
result = obj.CaptureActiveWindow()


1.2.4.
GetTextFromPoint method
HRESULT  GetTextFromPoint([in]  LONG  hwnd,  [in]  LONG  x,  [in]  LONG  y,
[out,retval] BSTR* result);

该方法通过在屏幕捕获点(x,y)的指定的字
坐标,由指定的窗口的HWND。
注:人们有可能利用CaptureIntercative方法来获取这些参数,
这是窗口句柄和坐标。

参数:
LONG hwnd : 处理窗口捕捉
LONG X : X坐标点
LONG Y : Y坐标点

BSTR* result : 这个字(如果有的话)在指定的点位于

例子:
Visual C++:

LONG hwnd = 0;
LONG X = 0;
LONG Y = 0;
//set the values
.......
bstr_t bstrResult = obj->GetTextFromPoint(hwnd, X, Y);
C#:
long hwnd = 0;
long X = 0;
long Y = 0;
//set the values
.......
string result = obj.GetTextFromPoint(hwnd, X, Y);
Visual Basic:
Dim result As String
Dim hwnd As Long
Dim X As Long
Dim Y As Long
'set the values
.......
result = obj.GetTextFromPoint(hwnd, X, Y)
1.2.5.
GetTextFromRect method
HRESULT GetTextFromRect([in] LONG hwnd, [in] LONG left, [in] LONG top,
[in] LONG width, [in] LONG height, [out,retval] BSTR* result);

这种方法捕获从指定的矩形文本(左,上,
宽度,高度屏幕)坐标,由指定的窗口的句柄。


注:人们有可能利用CaptureIntercative方法来获取这些参数,
这是窗口处理和协调.

参数:
LONG hwnd : 处理窗口捕捉
LONG left : X坐标上矩形的左上点
LONG top : Y坐标上矩形的左上点
LONG width : 矩形的宽度
LONG height : 矩形的高度
BSTR* result : 位于该地区的文本指定的矩形


例子:
Visual C++:

LONG hwnd = 0;
LONG left = 0;
LONG top = 0;
LONG width = 0;
LONG height = 0;
//set the values
.......
bstr_t bstrResult = obj->GetTextFromRect(hwnd, left, top,
width, height);
C#:
long hwnd = 0;
long left = 0;
long top = 0;
long width = 0;
long height = 0;
//set the values
.......
string result = obj.GetTextFromRect(hwnd, left, top, width,
height);
Visual Basic:
Dim result As String
Dim hwnd As Long
Dim left As Long
Dim top As Long
Dim width As Long
Dim height As Long
'set the values
.......
result
=
obj.GetTextFromRect(hwnd,
left,
top,
width,
height)















这个问题不想再去浪费时间了,能力不够,也不是非要弄会不可,感谢各位的关注,非常感谢
附件: 您需要 登录 才可以下载或查看,没有账号?加入

最佳答案

查看完整内容

http://www.autoitx.com/forum.php?mod=redirect&goto=findpost&ptid=17726&pid=198403&fromuid=7634069
发表于 2011-3-18 13:47:44 | 显示全部楼层
发表于 2011-3-18 21:03:29 | 显示全部楼层
$oTCaptureX=objcreate("TCaptureX.TextCaptureX")
;if isobj($oTCaptureX) then msgbox(0,"","OK")
$hdl=$oTCaptureX.GetActiveWindowHwnd
$str=$oTCaptureX.gettextfromrect($hdl,1,1,500,500)
msgbox(0,$hdl,$str)
后面四个参数用不明白,老是取不到内容。
$str=$oTCaptureX.CaptureInteractive($hdl,0,0,500,500)
加上这句可以手动选择区域,也不知道要怎么用,权当开拓一下大家的思路吧。

评分

参与人数 1金钱 +30 贡献 +5 收起 理由
tryhi + 30 + 5 感谢关注!

查看全部评分

 楼主| 发表于 2011-3-18 21:34:18 | 显示全部楼层
本帖最后由 tryhi 于 2011-3-18 21:37 编辑

回复 2# kevinch
有个问题,就是我运行这句
regsvr32 C:\TCaptureX.dll
却出现这个提示

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2011-3-18 23:12:11 | 显示全部楼层
回复 4# pusofalse

感谢P版先,我研究下,这两天咋给忘了搜索“取词”这个关键词呢。。。。
发表于 2011-3-19 07:04:26 | 显示全部楼层
回复  kevinch
有个问题,就是我运行这句却出现这个提示
tryhi 发表于 2011-3-18 21:34


楼主提供的那个独立的tcapturex.dll有问题,不能正常使用,请使用程序中的那个tcapturex.dll,那个是好的,我是用那个注册后使用的。

评分

参与人数 1金钱 +20 贡献 +2 收起 理由
tryhi + 20 + 2 怎么还是不行呢。。

查看全部评分

 楼主| 发表于 2011-3-19 11:39:00 | 显示全部楼层
本帖最后由 tryhi 于 2011-3-19 16:00 编辑
楼主提供的那个独立的tcapturex.dll有问题,不能正常使用,请使用程序中的那个tcapturex.dll,那个是好 ...
kevinch 发表于 2011-3-19 07:04


怎么我用程序里面那个注册仍然失败呢
 楼主| 发表于 2011-3-19 12:39:58 | 显示全部楼层
回复 4# pusofalse

P版这个确实令人佩服,只不过IE里的内容似乎没办法,只能取IE的工具栏那些,对于网页内容似乎无能为力,还是非常感谢
发表于 2011-3-19 13:26:50 | 显示全部楼层
安装Aqua1.3就可以正常注册

评分

参与人数 1金钱 +20 贡献 +2 收起 理由
tryhi + 20 + 2 感谢关注

查看全部评分

 楼主| 发表于 2011-3-19 16:07:46 | 显示全部楼层
回复 9# fyy6330

不是吧……那么麻烦的话真不想用
发表于 2011-3-19 18:06:19 | 显示全部楼层
回复  fyy6330

不是吧……那么麻烦的话真不想用
tryhi 发表于 2011-3-19 16:07


我就是用的你的程序压缩包中的那个点右键注册后使用的,没用安装程序。

评分

参与人数 1金钱 +30 贡献 +5 收起 理由
tryhi + 30 + 5 确实是这样

查看全部评分

发表于 2011-3-25 10:44:03 | 显示全部楼层
虽然用AU3暂时还不知道怎么使用,但是楼主的资源对我很有用,先用C#做做看。谢谢楼主

评分

参与人数 1贡献 +1 收起 理由
tryhi + 1 客气

查看全部评分

发表于 2011-3-25 12:59:59 | 显示全部楼层
好高深  直接看不懂。。。。
发表于 2011-3-25 19:38:57 | 显示全部楼层
本帖最后由 manlty 于 2011-3-25 19:40 编辑

早就有人做这个dll的au3程序调用了。不过这个速度有点慢。
说到快,还是p版以前写的那个内存取词的程序。好像还用到汇编。不过是用au3来做的。
希望P版能改一下,不仅仅是取一个词,最好是能取目标窗口内给定lef\top\width\height的矩形区域内的文字。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2011-3-25 21:24:01 | 显示全部楼层
回复 14# manlty

不明白你的意思,这个不是P版的那个么?没有调用DLL啊
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-10 05:10 , Processed in 0.080967 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表