请教如何获得窗口里面指定文档的内容
本帖最后由 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
回复 1# jackey009
看不大明白楼主的意思,不过如果要获得窗口里的指定内容,可以这样做;
if StringInStr(WinGetText("Windows Internet Explorer"), "定金金额小于未提量货款总金额") then
MsgBox(0, "读取的文本为:","读取到的文本为: " & WinGetText("Windows Internet Explorer"))
endif #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 Then Return SetError(1, 0, 0)
Return $hWnd
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 Then Return SetError(1, 0, 0)
Return $hWnd
EndFunc ;==>_FindWindowEx
楼主的意思是不是要取这个差额的金额。试一试用正则表达式匹配吧stringregExp() 楼上试试能不能取差后面的数字,取差后面的数字38600.28。我不知道怎么取。 我想取窗口里面,文本内容中差后面的数字。38600.28 回复 2# papapa314
不要全部内容,只要差后面部分有办法做到吗?请指教 不好意思,没看清楚要求.
小改一下
#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)
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 Then Return SetError(1, 0, 0)
Return $hWnd
EndFunc ;==>_FindWindowEx
没条件测试. 本帖最后由 jackey009 于 2011-2-11 09:27 编辑
回复 8# ceoguang
我试了返回错误,不知道什么原因,请指教。
那就将_WinAPI_FindWindow替换成3#的_FindWindow
页:
[1]