找回密码
 加入
搜索
查看: 5283|回复: 12

[IE类操作] [已解决]请教为什么AdlibRegister("MyAdlib")没有执行?

  [复制链接]
发表于 2011-10-17 10:53:52 | 显示全部楼层 |阅读模式
本帖最后由 彼岸天堂 于 2011-10-17 15:29 编辑

各位大侠,小弟是autoit新手,刚给一个系统写了一个自动化运行脚本,但是在“系统日切”被click后会弹出一个一个对话框从而是整个脚本暂停,我用了AdlibRegister(),但是好像没有执行,请大侠们帮忙看看,谢谢
#include <IE.au3>

$oIE = _IECreate ("http://38.19.7.69:9082/nbWeb",0,1,0,0)
Sleep(1000)
$oForm = _IEFormGetObjByName ($oIE, "commitForm")
$oQuery = _IEFormElementGetObjByName ($oForm, "oper_user_id")
_IEFormElementSetValue ($oQuery, "99999-99")
$oQuery = _IEFormElementGetObjByName ($oForm, "oper_pwd")
_IEFormElementSetValue ($oQuery, "888888")
_IEFormSubmit ($oForm, 0)
Sleep(1000)

$oIE = _IECreate("http://38.19.7.69:9082/nbWeb/management/duizhang/duizhang.jsp?func_id=1110321",0,1,0,0)
AdlibRegister("MyAdlib")
Sleep(1000)

;系统日切
$oForm = _IEFormGetObjByName ($oIE, "iForm")
$ID =_IEGetObjById ($oForm, "bt_on")
_IEAction($ID,"click")

Func MyAdlib()
        If WinActive("Microsoft Internet Explorer") Then
        Send("{enter}")
    EndIf
EndFunc
 楼主| 发表于 2011-10-17 11:01:28 | 显示全部楼层
自己顶下,大大们,求指教啊!
 楼主| 发表于 2011-10-17 11:07:01 | 显示全部楼层
再顶下,别沉啊,别沉
发表于 2011-10-17 11:51:35 | 显示全部楼层
弹出一个对话框使整个脚本暂停,MyAdlib() 当然不会执行。可以使用定时器之类的处理
 楼主| 发表于 2011-10-17 11:58:01 | 显示全部楼层
回复 4# afan
谢谢指导,那为什么AdlibRegister()没有执行了,按照帮助文档中的,它应该是250ms自动执行一次啊
发表于 2011-10-17 12:01:31 | 显示全部楼层
回复 5# 彼岸天堂


    脚本暂停了,所以 AdlibRegister() 也不会执行~
一楼的网址打不开,没法测试,大家也不好帮忙。你可以选个有弹出对话框窗口的网址做测试~
 楼主| 发表于 2011-10-17 12:05:54 | 显示全部楼层
回复 6# afan
哦,好的,我大概明白了,AdlibRegister()还是单线程,当脚本被暂停之后也是无法执行的,我这个问题大概要用的多线程来解决,请问有什么好的思路吗,我刚学没有多久,经验不足,谢谢了
发表于 2011-10-17 12:31:31 | 显示全部楼层
;定时器操作“中断操作的对话框”例子 By Afan

$title = 'C:\abcdefgg'                ;指定一个没有的路径做测试,接下来肯定会弹出一个错误。
_STimer($title, 'Windows ')        ;必须在弹窗之前

ShellExecute($title)                ;将会弹出错误消息框
Msgbox(64, 'ok', '脚本继续。(本例已完)')

Func _STimer($title, $text)
        Global $__title = $title, $__text = $text
        Global $__Timer = DllCallbackRegister('_Timer', 'int', 'hwnd;uint;uint;dword')
        Global $__TimerDLL = DllCall('user32.dll', 'uint', 'SetTimer', 'hwnd', 0, 'uint', _
                        0, 'int', 100, 'ptr', DllCallbackGetPtr($__Timer))
EndFunc   ;==>_STimer
Func _Timer($hwnd, $uiMsg, $idEvent, $dwTime)
        If $idEvent = $__TimerDLL[0] Then
                If WinExists($__title, $__text) Then
                        DllCallbackFree($__Timer)
                        MsgBox(262144 + 48, '错误消息框已弹出', '这个消息框是不需要的,仅此提示脚本在中断后仍会继续运行' & _
                                        @LF & '点击确定后继续下面的动作,Send("{enter}"')
                        Send("{enter}")
                EndIf
        EndIf
EndFunc   ;==>_Timer
发表于 2011-10-17 13:01:29 | 显示全部楼层
回复 7# 彼岸天堂
用循环扫描模式检测winactive
发表于 2011-10-17 14:32:47 | 显示全部楼层
本帖最后由 afan 于 2011-10-17 15:45 编辑

整了个函数 _WinAdlib,LZ可以测试下
#include <IE.au3>

$oIE = _IECreate ("http://38.19.7.69:9082/nbWeb",0,1,0,0)
Sleep(1000)
$oForm = _IEFormGetObjByName ($oIE, "commitForm")
$oQuery = _IEFormElementGetObjByName ($oForm, "oper_user_id")
_IEFormElementSetValue ($oQuery, "99999-99")
$oQuery = _IEFormElementGetObjByName ($oForm, "oper_pwd")
_IEFormElementSetValue ($oQuery, "888888")
_IEFormSubmit ($oForm, 0)
Sleep(1000)

_WinAdlib('Microsoft Internet Explorer', '', 'MyAdlib')
$oIE = _IECreate("http://38.19.7.69:9082/nbWeb/management/duizhang/duizhang.jsp?func_id=1110321",0,1,0,0)
;AdlibRegister("MyAdlib")
Sleep(1000)

;系统日切
$oForm = _IEFormGetObjByName ($oIE, "iForm")
$ID =_IEGetObjById ($oForm, "bt_on")
_IEAction($ID,"click")

Func MyAdlib()
        Send("{enter}")
EndFunc

; 函数名:_WinAdlib;=======================================================================
; 说明: 在弹窗出现时执行某个函数
; 语法: _WinAdlib('窗口标题', '窗口文本', '函数名'[, '超时'])
; 返回值:无
;====================================================================================start
Func _WinAdlib($title, $text, $Func, $timeout = 3000)
        Global $__title = $title, $__text = $text, $__Func = $Func, $__timeouts, $__timeout = $timeout
        Global $__Timer = DllCallbackRegister('__Timer', 'int', 'hwnd;uint;uint;dword')
        Global $__TimerDLL = DllCall('user32.dll', 'uint', 'SetTimer', 'hwnd', 0, 'uint', _
                        0, 'int', 100, 'ptr', DllCallbackGetPtr($__Timer))
EndFunc   ;==>_WinAdlib
Func __Timer($hwnd, $uiMsg, $idEvent, $dwTime)
        If $idEvent = $__TimerDLL[0] Then
                ;WinActive();WinExists
                If WinActive($__title, $__text) Then
                        DllCallbackFree($__Timer)
                        Call($__Func)
                Else
                        $__timeouts += 100
                        If $__timeouts >= $__timeout Then
                                DllCallbackFree($__Timer)
                        EndIf
                EndIf
        EndIf
EndFunc   ;==>__Timer

评分

参与人数 1金钱 +10 收起 理由
彼岸天堂 + 10 谢谢帮忙

查看全部评分

 楼主| 发表于 2011-10-17 14:41:49 | 显示全部楼层
回复 10# afan
感谢,中午吃饭和休息没有给您回复,万分感谢,我仔细研究和学习下。
发表于 2011-10-17 15:46:12 | 显示全部楼层
回复 11# 彼岸天堂


    10#之前少了个变量 $__timeouts,应该有问题,现在应该正常了
 楼主| 发表于 2011-10-17 21:12:23 | 显示全部楼层
回复 12# afan
好的,谢谢
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 21:16 , Processed in 0.078496 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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