找回密码
 加入
搜索
查看: 2814|回复: 9

[AU3基础] 请教如何获得窗口里面指定文档的内容

  [复制链接]
发表于 2011-2-10 13:42:16 | 显示全部楼层 |阅读模式
本帖最后由 jackey009 于 2011-2-10 15:34 编辑


请教如何获得这个窗口里面指定文档的内容,例如:38600.28.
自己做了个就是只能显示文档内的文本,不能指定文档内需要的内容。
WinActivate("Windows Internet Explorer","")
WinActive("Windows Internet Explorer","")

$text = WinGetText("Windows Internet Explorer", "")
if WinActivate("Windows Internet Explorer","定金金额小于未提量货款总金额")Then
MsgBox(0, "读取的文本为:","读取到的文本为: " & $text)
EndIf


我做的只能获取全部文档内容,不能截取 38600.28



本帖子中包含更多资源

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

×
发表于 2011-2-10 14:20:18 | 显示全部楼层
回复 1# jackey009


看不大明白楼主的意思,不过如果要获得窗口里的指定内容,可以这样做;
if StringInStr(WinGetText("Windows Internet Explorer"), "定金金额小于未提量货款总金额") then
MsgBox(0, "读取的文本为:","读取到的文本为: " & WinGetText("Windows Internet Explorer"))
endif
发表于 2011-2-10 14:25:01 | 显示全部楼层
#include<winapi.au3>


$Parent = _FindWindow("#32770", "Microsoft Internet Explorer")
If Not($Parent) Then Exit MsgBox(16,"错误","没找到对话框")
MsgBox(64,"找到文本",WinGetTitle(_WinAPI_GetWindow(_FindWindowEx("Static", "", $Parent),2)))

Func _FindWindow($sClass, $sTitle = "")
        Local $tClass = DllStructCreate("wchar[" & StringLen($sClass) + 1 & "]")
        DllStructSetData($tClass, 1, $sClass)

        Local $tTitle = DllStructCreate("wchar[" & StringLen($sTitle) + 1 & "]")
        DllStructSetData($tTitle, 1, $sTitle)

        Local $hWnd = DllCall("user32.dll", "hwnd", "FindWindowW", "ptr", DllStructGetPtr($tClass), "ptr", DllStructGetPtr($sTitle))

        If Not $hWnd[0] Then Return SetError(1, 0, 0)
        Return $hWnd[0]
EndFunc   ;==>_FindWindow

Func _FindWindowEx($lpszClass, $lpszWindow = "", $hWndParent = 0, $hWndChildAfter = 0)
        Local $tClass = DllStructCreate("wchar[" & StringLen($lpszClass) + 1 & "]")
        DllStructSetData($tClass, 1, $lpszClass)

        Local $tTitle = DllStructCreate("wchar[" & StringLen($lpszWindow) + 1 & "]")
        DllStructSetData($tTitle, 1, $lpszWindow)
        Local $hWnd = DllCall("user32.dll", "hwnd", "FindWindowExW", "hwnd", $hWndParent, "hwnd", $hWndChildAfter, "ptr", DllStructGetPtr($tClass), "ptr", DllStructGetPtr($tTitle))

        If Not $hWnd[0] Then Return SetError(1, 0, 0)
        Return $hWnd[0]
EndFunc   ;==>_FindWindowEx

评分

参与人数 1金钱 +10 收起 理由
jackey009 + 10

查看全部评分

发表于 2011-2-10 14:45:06 | 显示全部楼层
楼主的意思是不是要取这个差额的金额。试一试用正则表达式匹配吧  stringregExp()
 楼主| 发表于 2011-2-10 14:53:12 | 显示全部楼层
楼上试试能不能取差后面的数字,取差后面的数字38600.28。我不知道怎么取。
 楼主| 发表于 2011-2-10 15:06:17 | 显示全部楼层
我想取窗口里面,文本内容中差后面的数字。38600.28
 楼主| 发表于 2011-2-10 15:44:04 | 显示全部楼层
回复 2# papapa314


   不要全部内容,只要差后面部分有办法做到吗?请指教
发表于 2011-2-10 16:32:54 | 显示全部楼层
不好意思,没看清楚要求.
小改一下

#include<winapi.au3>


$Parent = _WinAPI_FindWindow("#32770", "Microsoft Internet Explorer")
If Not ($Parent) Then Exit MsgBox(16, "错误", "没找到对话框")
$Str = WinGetTitle(_WinAPI_GetWindow(_FindWindowEx("Static", "", $Parent), 2))
If $Str Then
        $Ret = StringRegExp($Str, '\d+(.\d+)?$', 2, 1)
        If Not @error Then MsgBox(64, "找到文本", $Ret[0])
EndIf

Func _FindWindowEx($lpszClass, $lpszWindow = "", $hWndParent = 0, $hWndChildAfter = 0)
        Local $tClass = DllStructCreate("wchar[" & StringLen($lpszClass) + 1 & "]")
        DllStructSetData($tClass, 1, $lpszClass)

        Local $tTitle = DllStructCreate("wchar[" & StringLen($lpszWindow) + 1 & "]")
        DllStructSetData($tTitle, 1, $lpszWindow)
        Local $hWnd = DllCall("user32.dll", "hwnd", "FindWindowExW", "hwnd", $hWndParent, "hwnd", $hWndChildAfter, "ptr", DllStructGetPtr($tClass), "ptr", DllStructGetPtr($tTitle))

        If Not $hWnd[0] Then Return SetError(1, 0, 0)
        Return $hWnd[0]
EndFunc   ;==>_FindWindowEx

没条件测试.
 楼主| 发表于 2011-2-11 09:23:11 | 显示全部楼层
本帖最后由 jackey009 于 2011-2-11 09:27 编辑

回复 8# ceoguang

我试了返回错误,不知道什么原因,请指教。





本帖子中包含更多资源

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

×
发表于 2011-2-11 14:12:01 | 显示全部楼层
那就将_WinAPI_FindWindow替换成3#的_FindWindow
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-21 13:36 , Processed in 0.085961 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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