找回密码
 加入
搜索
查看: 2380|回复: 7

[GUI管理] 检测标题、内容输出对应网页,标题不变的情况网页总是在刷新

[复制链接]
发表于 2017-4-6 11:09:09 | 显示全部楼层 |阅读模式
输出相同网页的时候,怎么能不刷新?弄了2天没弄明白。
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_Outfile=wo1.exe
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <array.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
$oIE = ObjCreate("Shell.Explorer.2")
Opt("GUIOnEventMode", 1)
opt('GUIResizeMode',1)
$Form1 = GUICreate("Form1",229, 214, 492, 256,0x00CF0000)
GUICtrlCreateObj($oIE, -1, -1,229, 214)
$flile="file://"&@ScriptDir
_SetWindowPos($Form1, 200, 200)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "_MainSwitch")
Global $oldte
Global $true
While 1
        $ti=WinGetTitle("")
         $te=WinGetText("")
        $text = IniReadSection(".\text.ini", "text")
If @error Then
MsgBox(4096, "", "错误, 读取text.ini文件失败.")
Else
                 For $i = 1 To $text[0][0]
                 
                                  $nn=StringInStr($te,$text[$i][0])
                                 $tt=StringInStr($ti,$text[$i][0])
                         If $nn<>0 Then                 $oIE.navigate($flile&'/'&$text[$i][1])
                         if $tt<>0 Then                 $oIE.navigate($flile&'/'&$text[$i][1])
          Next
endif
Sleep(1000)
       wend
Func _MainSwitch()
        Switch @GUI_CtrlId
                Case $GUI_EVENT_CLOSE
                        GUIDelete($Form1)
                        Exit
       EndSwitch
        EndFunc
        Func _SetWindowPos($hWnd, $x, $y) ;使用API将窗体保持最前  
Local $cX, $cY  
Dim $hWndInsertAfter = -1  
Dim $wFlags = 1  
DllCall("user32.dll", "long", "SetWindowPos", "long", $hWnd, "long", $hWndInsertAfter, "long", $x, _  
   "long", $y, "long", $cX, "long", $cY, "long", $wFlags)  
EndFunc   ;==>_SetWindowPos



调用的ini文件信息 文件名 text.ini
文件内容
[text]
请查看标准码与录入码是否有空值!=12.mht
科室资料维护=12.mht
护理站维护=18.mht
管理系统=115.mht

做个简单的帮助系统,切换到不同窗口检查标题,文本,显示帮助信息。标题不变的情况下,程序窗口不停的刷新网页,不知道怎么处理
试过exitloop,没弄明白。当时操作过的窗口第一遍能正常显示,再进入重复的窗口就不动了。
 楼主| 发表于 2017-4-6 15:22:54 | 显示全部楼层
自己处理了一下,思路就是循环等待1秒后,再取一个窗口标题,然后跟最开始的标题比对,相同就ContinueLoop,返回上一层继续判断
刚开始几个变量用的global,程序不稳定,有时候切换窗口不判断,替换成Static,试了几次暂时没问题。现在的方案也不完美,就是可用性高一些了。
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_Outfile=wo1.exe
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <array.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
$oIE = ObjCreate("Shell.Explorer.2")
Opt("GUIOnEventMode", 1)
opt('GUIResizeMode',1)
$Form1 = GUICreate("Form1",229, 214, 492, 256,0x00CF0000)
GUICtrlCreateObj($oIE, -1, -1,229, 214)
$flile="file://"&@ScriptDir
_SetWindowPos($Form1, 200, 200)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "_MainSwitch")
Static $te  ;修改点
Static $true ;修改点
Static $ti ;修改点
Static $oti ;修改点
Static $ote ;修改点
While 1
        $ti=WinGetTitle("")
    $te=WinGetText("")
If  $ti=$oti Then ContinueLoop ;修改点 判断窗口标题如果一样,返回上层获取窗口标题
;If  $te=$ote Then ContinueLoop ;修改点 这个判断没实际意义,屏蔽了
$text = IniReadSection(".\text.ini", "text")

If @error Then
MsgBox(4096, "", "错误, 读取text.ini文件失败.")
Else
         
         
                 For $i = 1 To $text[0][0]
                         $nn=StringInStr($te,$text[$i][0])
                                $tt=StringInStr($ti,$text[$i][0])
                        If $nn<>0 Then         $oIE.navigate($flile&'/'&$text[$i][1])
                        if $tt<>0 Then        $oIE.navigate($flile&'/'&$text[$i][1])
                Next

endif
       
Sleep(1000)
$oti=WinGetTitle("")  ;修改点
;$ote=WinGetText("") ;修改点 没实际意义屏蔽了
       wend
          
Func _MainSwitch()
        Switch @GUI_CtrlId
                Case $GUI_EVENT_CLOSE
                        GUIDelete($Form1)
                        Exit
       EndSwitch
        EndFunc
        Func _SetWindowPos($hWnd, $x, $y) ;使用API将窗体保持最前  
Local $cX, $cY  
Dim $hWndInsertAfter = -1  
Dim $wFlags = 1  
DllCall("user32.dll", "long", "SetWindowPos", "long", $hWnd, "long", $hWndInsertAfter, "long", $x, _  
   "long", $y, "long", $cX, "long", $cY, "long", $wFlags)  
EndFunc   ;==>_SetWindowPos
 楼主| 发表于 2017-4-6 16:05:54 | 显示全部楼层
还是有问题,我切换帮助窗口,跟程序的时候,还是会刷新,效果不好。
 楼主| 发表于 2017-4-6 16:48:56 | 显示全部楼层
又改了一下,这次检查输出的文件名,按文件名判断的,这次效果挺好,目前测试都很好。多数代码都是从论坛里抄来的,感谢论坛提供的代码
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_Outfile=wo1.exe
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <array.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
$oIE = ObjCreate("Shell.Explorer.2")
Opt("GUIOnEventMode", 1)
opt('GUIResizeMode',1)
$Form1 = GUICreate("xx帮助系统",229, 214, 492, 256,0x00CF0000)
GUICtrlCreateObj($oIE, -1, -1,229, 214)
$flile="file://"&@ScriptDir
_SetWindowPos($Form1, 200, 200)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "_MainSwitch")
Static $te
Static $ti
Static $oti="0"
Static $ote
Static $dte
While 1
       
        $ti=WinGetTitle("")
    $te=WinGetText("")
;If  $ti=$oti Then ContinueLoop

;If  $te=$ote Then ContinueLoop
$text = IniReadSection(".\text.ini", "text")

If @error Then
MsgBox(4096, "", "错误, 读取text.ini文件失败.")
Else
         
                 For $i = 1 To $text[0][0]
                         $nn=StringInStr($te,$text[$i][0])
                                $tt=StringInStr($ti,$text[$i][0])
                        If $nn<>0 Then        
                                If $dte=$text[$i][1] Then exitLoop  ;用过期文件名,对比取得的文件名
                        $oIE.navigate($flile&'/'&$text[$i][1])
                            $ote=$text[$i][1]   ;向变量传递过期文件名
                        endif
                        if $tt<>0 Then       
                        If $dte=$text[$i][1] Then ContinueLoop ;用过期文件名,对比取得的文件名
                        $oIE.navigate($flile&'/'&$text[$i][1])
                                $ote=$text[$i][1]  ;向变量传递过期文件名
                endif
       
                Next
        endif
       
Sleep(1000)
;$oti=WinGetTitle("")  ;作废命令
$dte=$ote   ; 传递过期文件名

       wend
          
Func _MainSwitch()
        Switch @GUI_CtrlId
                Case $GUI_EVENT_CLOSE
                        GUIDelete($Form1)
                        Exit
       EndSwitch
        EndFunc
        Func _SetWindowPos($hWnd, $x, $y) ;使用API将窗体保持最前  
Local $cX, $cY  
Dim $hWndInsertAfter = -1  
Dim $wFlags = 1  
DllCall("user32.dll", "long", "SetWindowPos", "long", $hWnd, "long", $hWndInsertAfter, "long", $x, _  
   "long", $y, "long", $cX, "long", $cY, "long", $wFlags)  
EndFunc   ;==>_SetWindowPos
发表于 2017-4-7 11:16:00 | 显示全部楼层
本帖最后由 1361739590 于 2017-4-7 11:19 编辑

说实话  读你的内容有点费力。
功能是循环显示text.ini里面设定的几个页面?
可以把功能说清楚一点,特别是 Else 后面想做什么。
 楼主| 发表于 2017-4-7 22:20:41 | 显示全部楼层
本帖最后由 pingguo002 于 2017-4-7 22:37 编辑

对,功能就是捕捉的窗口的  标题  文本,循环比对,找到对应的网页显示出来。
$ti=WinGetTitle("")
$te=WinGetText("")
已经解决了,最后发的代码能用。


For $i = 1 To $text[0][0] ;循环对比text.ini文件
$nn=StringInStr($te,$text[$i][0]) ;找到对应的标题
$tt=StringInStr($ti,$text[$i][0]) ;找到对应的文本
If $nn<>0 Then  ;判断text.ini的某行和包含标题(如果=0就是不包含,所以用<>;“不等于”的符号用没有其他写法?)
If $dte=$text[$i][1] Then exitLoop;$dte第一次循环没有值,肯定false,在后面循环一次输出网页后才会有值,这个是检查第2次及以后,输出的网页跟现在显示的网页是否一样,一样就跳出循环
$oIE.navigate($flile&'/'&$text[$i][1]) ;输出对应网页
$ote=$text[$i][1];第一次输出网页后,传递一个值给第二次循环后做对比
endif
if $tt<>0 Then;同上 对比 文本;
If $dte=$text[$i][1] Then ContinueLoop ;同上 判断第二次循环值
$oIE.navigate($flile&'/'&$text[$i][1])
$ote=$text[$i][1;同上 第一次输出网页后,把网页传递出来。
endif
Next
endif
Sleep(1000)
$dte=$ote;传递最后输出的网页值,为第二次循环使用。(感觉把值弄出循环外保险,在循环内判断不清值的变化)



最开始写的时候,用了两个for 循环,一个对比标题,一个对比文本。
最后简化代码写成这样了,用了一个for循环
发表于 2017-4-7 22:30:52 | 显示全部楼层
循环关闭试试
 楼主| 发表于 2017-4-7 22:34:58 | 显示全部楼层
说一下思路
问题:
检测到一个标题,输出一个网页,循环一次后又检测到相同的标题,输出了一个相同的网页,造成不停输出网页刷新。
结果:标题没变,网页不停的刷新

解决方案:
检测标题,相同标题不输出,试过n种方法失败
检测输出的网页,相同网页不输出。试过do until 没弄明白,反正不好使
试过n种方法后,发现sleep(1000)后,可以设置一个稳定值,用于对比新输出的网页搞定

exitloop  continueloop 这两个语句怎么运作不是很清楚,不知道是跳到哪了,反正程序是好用了。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-20 16:24 , Processed in 0.085289 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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