本帖最后由 地平线 于 2012-5-24 23:41 编辑
回复 29# 秋无痕
这个主要用模拟鼠标点击,技术含量不大。其中的那个点击托盘图标的UDF是直接用别人的。
#Include <GuiToolBar.au3>
Global $hSysTray_Hide_Handle
Global $iSystrayHide_ButtonNumber
Global $hSysTray_Handle
BlockInput(1) ;屏蔽用户输入
_ClickSysTrayIcon("金山毒霸","right") ;右键点击托盘图标
Sleep(200)
;$size =WinGetPos("[ACTIVE]")
;MsgBox(0,'',$size[2]&@CRLF&$size[3]) ;获得右键菜单的尺寸为160x350
AutoItSetOption("MouseCoordMode", 0)
MouseClick("left",50,270) ;点击右键菜单的设置选项
WinWaitActive("设置")
AutoItSetOption("PixelCoordMode", 0)
If PixelGetColor(180,230) = 0x21A121 Then
MouseClick("left",180,230)
EndIf
Sleep(200)
MouseClick("left",60,370)
Sleep(200)
If PixelGetColor(190,260) = 0x21A121 Then
MouseClick("left",190,260)
EndIf
If PixelGetColor(190,360) <> 0x21A121 Then
MouseClick("left",190,360)
EndIf
If PixelGetColor(390,360) <> 0x21A121 Then
MouseClick("left",390,360)
EndIf
If PixelGetColor(189,386) <> 0x21A121 Then
MouseClick("left",189,386)
EndIf
Sleep(200)
MouseClick("left",435,450) ;最后确定
BlockInput(0) ;启用用户输入
Func _ClickSysTrayIcon($sToolTipTitle,$Button)
$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)
If ControlCommand("[class:Shell_TrayWnd]","","Button1","IsVisible","") And $iSystray_ButtonNumber = -1 Then
ClickHideIcon($sToolTipTitle,$Button)
Else
ClickDisplayIcon($sToolTipTitle,$Button)
EndIf
EndFunc
Func ClickDisplayIcon($sToolTipTitle,$Button)
$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)
If $iSystray_ButtonNumber = -1 Then
Return 0
Else
Sleep(500)
_GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, $Button, True, 1, 20)
EndIf
EndFunc
Func ClickHideIcon($sToolTipTitle,$Button)
$hSysTray_Hide_Handle1 = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:Button;Instance:1]')
_GUICtrlToolbar_ClickButton($hSysTray_Hide_Handle1, "Button1", "Left", True, 1, 20)
Sleep(500)
$iSystray_ButtonNumber = Get_Hide_Systray_Index($sToolTipTitle)
If $iSystray_ButtonNumber = -1 Then
Return 0
Else
Sleep(500)
_GUICtrlToolbar_ClickButton($hSysTray_Hide_Handle, $iSystray_ButtonNumber, $Button, True, 1, 20)
EndIf
$iSystray_ButtonNumber = Get_Hide_Systray_Index($sToolTipTitle)
EndFunc
Func Get_Systray_Index($sToolTipTitle)
$hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
If @error Then
Return 0
EndIf
Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
If $iSystray_ButCount = 0 Then
Return 0
EndIf
For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) = 1 Then ExitLoop
Next
If $iSystray_ButtonNumber = $iSystray_ButCount Then
Return -1
Else
Return $iSystray_ButtonNumber
EndIf
EndFunc
Func Get_Hide_Systray_Index($sToolTipTitle)
$hSysTray_Hide_Handle = ControlGetHandle('[Class:NotifyIconOverflowWindow]', '', '[Class:ToolbarWindow32;Instance:1]')
If @error Then
Return 0
EndIf
Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Hide_Handle)
If $iSystray_ButCount = 0 Then
Return 0
EndIf
For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Hide_Handle, $iSystray_ButtonNumber),$sToolTipTitle) Then ExitLoop
Next
If $iSystray_ButtonNumber = $iSystray_ButCount Then
Return -1
Else
Return $iSystray_ButtonNumber
EndIf
EndFunc
|