【已解决】如何捕捉窗口主题变化信息?
本帖最后由 lion.lee 于 2012-3-1 11:36 编辑工作需要controldisable专业软件上的按钮,使用while 1循环,待目标窗口被激活时调用controldisable命令,但假如该窗口一直被激活的话就会反复执行,造成CPU占用太高。
我的目标是:
1、同一窗口只执行一次;
2、当窗口主题变化时再执行;
问题点:
不能用winsettile命令改变该窗口主题,因为下一个需要执行该命令的窗口前缀与前一个窗口一样。我使用的判断是否执行的条件是 if winactive(),要是窗口主题改变了的话,下次满足条件的其他窗口就无法执行。
写的有点乱,不知道有没有前辈能给点指导,谢谢! 使用窗口句柄来处理试试. “当窗口主题变化时再执行” 什么变化? 回复 3# afan
ex:
1、目前窗口“目标窗口-1”,符合“if winactive("目标窗口","") then controldisable 相关按钮”条件,只需要执行一次命令,但若当前窗口一直处于激活状态的话就会反复执行命令;
2、软件进行别的操作时不符合if条件,程序不执行名利;
3、当窗口变成“目标窗口-2”时,同样能触发命令;
4、所以我想当符合条件的窗口一直处于激活状态时,命令不重复执行;
不知道这次描述清楚了没有?呵呵! “2、软件进行别的操作时不符合if条件,程序不执行名利” 程序很淡定是吧…
为何不符合if条件? 本帖最后由 lion.lee 于 2012-2-21 21:25 编辑
回复 5# afan
笔误,呵呵!版版真幽默。
我把源码给版版看看。#region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=C:\Program Files\SIPLACE\SIPLACE Pro\Siemens.SIPLACEPro.ReportTool.exe|-1
#endregion ;**** 参数创建于 ACNWrapper_GUI ****
#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1_1 = GUICreate("调程序提醒", 627, 540)
$Edit1 = GUICtrlCreateEdit("", -24, 32, 649, 505, BitOR($ES_CENTER, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN))
GUICtrlSetData(-1, StringFormat("\r\n\r\n请确认是否有:\r\n\r\n临改需要执行?\r\n\r\n有同名Board?"))
GUICtrlSetFont(-1, 36, 400, 0, "黑体")
GUICtrlSetBkColor(-1, 0xFF0000)
GUISetState()
Send("{END}")
$Button1 = GUICtrlCreateButton("", 0, 0, 625, 33)
GUICtrlSetFont(-1, 16, 800, 0, "宋体")
GUISetState(@SW_HIDE)
HotKeySet("^{f1}", "_exit")
$file = "C:\WINDOWS\Pro guard"
If FileExists($file) = 0 Then
FileCopy(@ScriptFullPath, "C:\WINDOWS", 1)
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "Pro Safe Tool", "REG_SZ", $file)
EndIf
While 1
$nMsg = GUIGetMsg()
;主要是以下的代码会反复的执行:
If WinActive("SIPLACE Pro Desk", "Dipping is required") Then
For $m = 1 To 100
$text = ControlGetText("SIPLACE Pro Desk", "Dipping is required", "WindowsForms10.BUTTON.app.0.33c0d9d" & $m)
If $text = "Non polarized" Or $text = "Omit" Or $text = "Place" Then ControlDisable("SIPLACE Pro Desk", "Dipping is required", "WindowsForms10.BUTTON.app.0.33c0d9d" & $m)
Next
$title = WinGetTitle("SIPLACE Pro Desk", "Dipping is required")
While WinActive($title, "Dipping is required")
Sleep(100)
WEnd
EndIf
If WinActive("SIPLACE Pro Desk", "Enable centering") Then
For $n = 1 To 100
$textcenter = ControlGetText("SIPLACE Pro Desk", "Enable centering", "WindowsForms10.BUTTON.app.0.33c0d9d" & $n)
If $textcenter = "Enable centering" Then ControlDisable("SIPLACE Pro Desk", "Enable centering", "WindowsForms10.BUTTON.app.0.33c0d9d" & $n)
Next
$title = WinGetTitle("SIPLACE Pro Desk", "Enable centering")
While WinActive($title, "Enable centering")
Sleep(100)
WEnd
EndIf ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
If WinActive("Data Model Import Wizard - Step 4 of 5", "") Then
BlockInput(1)
WinSetState("Data Model Import Wizard - Step 4 of 5", "", @SW_MINIMIZE)
GUISetState(@SW_SHOW)
For $i = 3 To 0 Step -1
GUICtrlSetData($Button1, "键盘鼠标锁定倒计时:" & $i)
Sleep(1000)
Next
GUICtrlSetData($Button1, "")
GUISetState(@SW_HIDE)
WinActivate("Data Model Import Wizard", "")
BlockInput(0)
While WinExists("Data Model Import Wizard - Step 4 of 5", "")
Sleep(100)
WEnd
EndIf
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _exit()
Exit
EndFunc ;==>_exit
不知道版版理解我什么意思了没? 主循环里面带那么多死循环…
鸟语太多,看得头大,重复内容用变量吧 26-71行替换成以下试试Local $Tit = 'SIPLACE Pro Desk', $Txt = 'Dipping is required', $Txt1 = 'Enable centering'
Local $sCon = 'WindowsForms10.BUTTON.app.0.33c0d9d'
Local $Tit1 = 'Data Model Import Wizard - Step 4 of 5'
While 1
If Not IsDeclared($Tit & $Txt) And WinActive($Tit, $Txt) Then
For $m = 1 To 100
$text = ControlGetText($Tit, $Txt, $sCon & $m)
If $text = 'Non polarized' Or $text = 'Omit' Or $text = 'Place' Then _
ControlDisable($Tit, $Txt, $sCon & $m)
Next
Assign($Tit & $Txt, 1)
ElseIf Not IsDeclared($Tit & $Txt1) And WinActive($Tit, $Txt1) Then
For $n = 1 To 100
$textcenter = ControlGetText($Tit, $Txt1, $sCon & $n)
If $textcenter = $Txt1 Then _
ControlDisable($Tit, $Txt1, $sCon & $n)
Next
Assign($Tit & $Txt1, 1)
ElseIf Not IsDeclared($Tit1) And WinActive($Tit1, '') Then
BlockInput(1)
WinSetState($Tit1, '', @SW_MINIMIZE)
GUISetState(@SW_SHOW)
For $i = 3 To 0 Step -1
GUICtrlSetData($Button1, '键盘鼠标锁定倒计时:' & $i)
Sleep(1000)
Next
GUICtrlSetData($Button1, '')
GUISetState(@SW_HIDE)
WinActivate('Data Model Import Wizard', '')
BlockInput(0)
Assign($Tit1, 1)
EndIf
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd不成功的话我也没办法,完全不知道你那边的状况 多谢afan版主的帮忙,该问题目前没有解决。我自己再看看! 是啊,这个我老搞错 我又测试了一下,用了afan版主的if...elseif...elseif...endif后,CPU明显降低,已经达到了我的要求。谢谢! example is good.thanks~~~~~~~~~~~
页:
[1]