在论坛上找了一些作品套用了一下,发现当点击按钮,跳出input框后,无论选择确定或者取消,当鼠标移到屏幕右侧,主界面都无法自动出现了,要用鼠标按住一下才能出来,求教我的RunButton函数哪里错了?
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>
#include <Timers.au3>
Opt("GUIOnEventMode", 1)
HotKeySet("{ESC}", "_Exit")
If _Singleton(@ScriptName, 1) = 0 Then
MsgBox(0, "警告", "你只能启动该应用程序一次!")
Exit (1)
EndIf
Global $IniName = ""
Global $Z
$Z=10
;=========界面参数==================
Dim $LabelArray[$Z + 4][2]
Dim $Over[$Z + 2]
Dim $Pressed[$Z + 2]
Global Const $AC_SRC_ALPHA = 1
Global Const $Sensitivity = 10
Global Const $GWidth = 167
Global Const $GHeight = 120 + $Z * 41
Global $PosX = @DesktopWidth - 267
Global $PosY = (@DesktopHeight - 120 - $Z * 41)/2
Global $Pause = 0
Global $LastActiveWindow = ""
Global $Offline = 1
Global $LastPassBut=0
$SN=''
;=========自动隐藏参数============
$steps = 10
$dockvalue = 20
$allowdock = 4
$hidevalue = 5
$showdelay = 0
$hidedelay = 10
$dock = 0
$timer = 0
$time = 0
$animationfinished = False
$mousechecktimeron = False
$mouseinwindow = False
$show = True
;=========数据库==========
Global $RS
Global $Conn
GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING")
$Form1 = GUICreate("Main", $GWidth, $GHeight, $PosX, $PosY, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
;~ $Form1 = GUICreate("Main", $GWidth, $GHeight, $PosX, $PosY)
GUISetState(@SW_SHOW, $Form1)
$NumberTxt=GUICtrlCreateInput("", 12, 9 , 144, 36)
GUICtrlSetFont(-1, 16)
For $i = 1 To $Z
$LabelArray[$i][0] = GUICtrlCreateButton("步骤 " & $i, 12, 49 + ($i - 1) * 41, 144, 36)
Next
$LabelArray[$Z + 1][0] = GUICtrlCreateButton("退出", 96, 49 + $Z * 41, 60, 36);退出标签
$LabelArray[$Z + 2][0] = GUICtrlCreateLabel("111", 19, 54 + $Z * 41, 87, 13, BitOR($SS_CENTER, $SS_CENTERIMAGE));状态标签
GUICtrlSetFont(-1, 8)
$LabelArray[$Z + 3][0] = GUICtrlCreateLabel("2222", 19, 66 + $Z * 41, 87, 13, BitOR($SS_CENTER, $SS_CENTERIMAGE));使用标签
GUICtrlSetFont(-1, 8)
GUICtrlSetState($LabelArray[1][0],$GUI_FOCUS)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "PRIMARYDOWN")
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "SetCheckMouseTimer")
GUICtrlSetOnEvent($LabelArray[$Z + 1][0], "_Exit")
While 1
Sleep(1)
WEnd
Func RunButton($ButtonNumber)
MouseClick('primary',@DesktopWidth/2,@DesktopHeight/2)
Sleep(1000)
Switch $ButtonNumber
Case 1 To $Z
If $ButtonNumber = 1 Then
$SNTxt = InputBox("信息输入框", "扫入条码", "", "", -1, -1)
If (@error = 0) And ($SNTxt <> '') Then
$SN = $SNTxt
$LastPassBut=0
ConsoleWrite($SN)
Else
ConsoleWrite(@CRLF&@error&@CRLF)
Return 0
EndIf
EndIf
If $SN <>'' Then
For $J = $ButtonNumber To $Z
$Flag = MsgBox(4 + 32 + 262144, "信息提示框", "是否继续进行第"&$J&"项的测试")
If $Flag = 7 Then
GUICtrlSetState($LabelArray[$J][0],$GUI_FOCUS)
Return
EndIf
If $LastPassBut<>$J-1 Then
MsgBox(0+48+262144,"信息提示框", "请上一Pass的测试项加一开始测试")
GUICtrlSetState($LabelArray[$J][0],$GUI_FOCUS)
Return
EndIf
;~ Opterate($J)
$LastPassBut=$J
Next
If $LastPassBut=$Z Then
;~ $SN=''
;~ $LastPassBut=0
;~ $add = 'update testinfo set funcresult=''1'' where serialid='''& $SN&''''
;~ $Conn.Execute($add)
;开始下一个测试
RunButton(1)
EndIf
Else
MsgBox(0+48+262144,"信息提示框", "请从步骤一开始测试")
Return
EndIf
;~ MsgBox(0, "", "You Pressed Button " & $ButtonNumber)
Case $Z + 1
Exit
EndSwitch
EndFunc
Func PRIMARYDOWN()
$CursorInfo = GUIGetCursorInfo($Form1)
For $i=1 To $Z+1
If $CursorInfo[4] = $LabelArray[$i][0] Then ;光标在按钮
RunButton($i)
EndIf
Next
KillAnimationTimer()
KillCheckMouseTimer()
_SendMessage($Form1, $WM_NCLBUTTONDOWN, $HTCAPTION, 0)
EndFunc
Func CheckMouse()
If $dock = 0 Then Return
$winpos = WinGetPos($Form1)
Dim $mouseinwindow1 = MouseContains($winpos)
If BitXOR($mouseinwindow1, $mouseinwindow) Then $time = _Timer_Init()
$mouseinwindow = $mouseinwindow1
If $mouseinwindow1 Then
If Not $show And _Timer_Diff($time) > $showdelay Then
$show = True
SetAnimationTimer()
EndIf
Else
If $show And _Timer_Diff($time) > $hidedelay Then
$show = False
SetAnimationTimer()
EndIf
EndIf
EndFunc ;==>CheckMouse
Func SetAnimationTimer()
$animationfinished = False
If $timer = 0 Then $timer = _Timer_SetTimer($Form1, 5, "DoAnimation")
EndFunc ;==>SetAnimationTimer
Func KillAnimationTimer()
If $timer <> 0 Then
$timer = _Timer_KillTimer($Form1, $timer)
$timer = 0
EndIf
$animationfinished = True
EndFunc ;==>KillAnimationTimer
Func SetCheckMouseTimer()
If Not $mousechecktimeron Then AdlibRegister("CheckMouse", 75)
$mousechecktimeron = True
EndFunc ;==>SetCheckMouseTimer
Func KillCheckMouseTimer()
If $mousechecktimeron Then AdlibUnRegister("CheckMouse")
$mousechecktimeron = False
EndFunc ;==>KillCheckMouseTimer
Func MouseContains($winpos)
$pos = MouseGetPos()
Return $pos[0] >= $winpos[0] And $pos[0] <= $winpos[0] + $winpos[2] And $pos[1] >= $winpos[1] And $pos[1] <= $winpos[1] + $winpos[3]
EndFunc ;==>MouseContains
Func WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)
If $timer <> 0 Then Return
$rect = DllStructCreate($tagWINDOWPOS, $lParam)
$x = DllStructGetData($rect, "X")
$y = DllStructGetData($rect, "Y")
$width = DllStructGetData($rect, "CX")
$height = DllStructGetData($rect, "CY")
Local $move = 0
$dock = 0
$workarea = _GetWorkArea()
$move = 1
If BitAND($allowdock, 1) And $x <= $dockvalue And $x <> 0 Then
$x = 0
$dock = 1
$move = 1
EndIf
If BitAND($allowdock, 4) And @DesktopWidth - $x - $width <= $dockvalue And $x + $width - @DesktopWidth <> 0 Then
$x = @DesktopWidth - $width
$dock = 3
$move = 1
EndIf
If BitAND($allowdock, 2) And $y <= $dockvalue And $y <> 0 Then
$y = 0
$dock = 2
$move = 1
EndIf
If BitAND($allowdock, 8) And $workarea[3] - $y - $height <= $dockvalue And $y + $height - $workarea[3] <> 0 Then
$y = $workarea[3] - $height
$dock = 4
$move = 1
EndIf
If $move = 1 Then
DllStructSetData($rect, "X", $x)
DllStructSetData($rect, "Y", $y)
$hide = False
EndIf
EndFunc ;==>WM_WINDOWPOSCHANGING
Func _GetWorkArea()
Local Const $SPI_GETWORKAREA = 48
Local $rect[4]
Local $stRect = DllStructCreate("long left;long top;long right;long bottom")
Local $iResult = _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($stRect), 0)
If $iResult = True Then
$rect[0] = DllStructGetData($stRect, "left")
$rect[1] = DllStructGetData($stRect, "top")
$rect[2] = DllStructGetData($stRect, "right")
$rect[3] = DllStructGetData($stRect, "bottom")
Return $rect
Else
Return 0
EndIf
EndFunc ;==>_GetWorkArea
Func DoAnimation($hWnd, $Msg, $iIDTimer, $dwTime);自动隐藏关键函数
If $animationfinished Then Return
Global $show
$winpos = WinGetPos($Form1)
$newx = $winpos[0]
$newy = $winpos[1]
$width = $winpos[2]
$height = $winpos[3]
Switch $dock
Case 1, 3
$step = $winpos[2] / $steps
Case 2, 4
$step = $winpos[3] / $steps
Case Else
Return
EndSwitch
Switch $dock
Case 1
If $show Then
$newx += $step
If $newx > 0 Then
$newx = 0
$animationfinished = True
EndIf
Else
$newx -= $step
If $newx + $width < $hidevalue Then
$newx = -$width + $hidevalue
$animationfinished = True
EndIf
EndIf
Case 2
If $show Then
$newy += $step
If $newy > 0 Then
$newy = 0
$animationfinished = True
EndIf
Else
$newy -= $step
If $newy + $height < $hidevalue Then
$newy = -$height + $hidevalue
$animationfinished = True
EndIf
EndIf
Case 3
If $show Then
$newx -= $step
If $newx + $width < @DesktopWidth Then
$newx = @DesktopWidth - $width
$animationfinished = True
EndIf
Else
$newx += $step
If $newx > @DesktopWidth - $hidevalue Then
$newx = @DesktopWidth - $hidevalue
$animationfinished = True
EndIf
EndIf
Case 4
$workarea = _GetWorkArea()
$workareaHeight = $workarea[3]
If $show Then
$newy -= $step
If $newy + $height < $workareaHeight Then
$newy = $workareaHeight - $height
$animationfinished = True
EndIf
Else
$newy += $step
If $newy > $workareaHeight - $hidevalue Then
$newy = $workareaHeight - $hidevalue
$animationfinished = True
EndIf
EndIf
EndSwitch
WinMove($Form1, "", $newx, $newy)
If $animationfinished Then KillAnimationTimer()
EndFunc ;==>DoAnimation
Func _Exit()
Exit
EndFunc
|