Jump to content
Sign in to follow this  
anks

System Tray click does not work always

Recommended Posts

anks

Hi All,

Objective: Need to find a Application named "True Color Finder" running in the system tray of Win XP-32 bit and clicking left click , so that context menu opens up.

Script used:

#Include <GuiToolBar.au3>

Opt("WinTitleMatchMode", 2)
Global $hSysTray_Handle, $iSysTray_ButtonNumber
Global $sToolTipTitle = "True Color Finder"
$iSysTray_ButtonNumber = Get_SysTray_Index($sToolTipTitle)
If $iSysTray_ButtonNumber = 0 Then
MsgBox(16, "Error", "Is True Color Finder Running?")
Exit
Else
Sleep(500)
_GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSysTray_ButtonNumber, "right")
Sleep(2000)
;_GUICtrlToolbar_ClickIndex($hSysTray_Handle,2)
Send("{UP}")
Send("{UP}")
;Sleep(2000)
Send("{ENTER}")
;_GUICtrlToolbar_ClickIndex($hSysTray_Handle,2, "left", True)
Sleep(1000)
;~ $ret = _GUICtrlToolbar_GetButtonText($hSysTray_Handle,"#32768")
;~ msgbox(0,"",$ret)
EndIf

Func Get_SysTray_Index($sToolTipTitle)
; Find systray handle
$hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[CLASS:ToolbarWindow32; INSTANCE:1]')
If @error Then
     MsgBox(16, "Error", "System tray not found")
     Exit
EndIf
; Get systray item count
Local $iSysTray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
If $iSysTray_ButCount = 0 Then
     MsgBox(16, "Error", "No items found in system tray")
     Exit
EndIf
; Look for wanted tooltip
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 0 ; Not found
Else
     Return $iSysTray_ButtonNumber ; Found
EndIf
EndFunc

Problem Statement: The script above works only in few monitors, for other monitors it does not work.

Anybody can please provide me help regarding it, i believe that there are some settings changes on the monitor which needs to be done. Can any body guide me regarding the setting changes.

Resolution of monitor where the script runs: 1280 x 768.

Resolution of monitor where the script does not run: 1920 x 1080.

Thank you all of you.

Share this post


Link to post
Share on other sites
Melba23

anks,

I recognise that code! ;)

I do not think that the resolution of the screen should affect the code as the code used in _GUICtrlToolbar_ClickButton relies on the API to determine the button position. If you run this version of the script, does the mouse move to the correct place on the screen? :huh:

If $iSysTray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Is True Color Finder Running?")
    Exit
Else
    $tRect = _GUICtrlToolbar_GetButtonRectEx($hSysTray_Handle, $iSysTray_ButtonNumber)
    $tPoint = _WinAPI_PointFromRect($tRect)
    $tPoint = _WinAPI_ClientToScreen($hSysTray_Handle, $tPoint)
    Local $iX, $iY
    _WinAPI_GetXYFromPoint($tPoint, $iX, $iY)
    MouseMove($iX, $iY)
EndIf

Please let us know what happens. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
anks

@Melba23

I have integrated your code with mine...and it goes as below:

#Include <GuiToolBar.au3>

Opt("WinTitleMatchMode", 2)
Global $hSysTray_Handle, $iSysTray_ButtonNumber
Global $sToolTipTitle = "True Color Finder"
$iSysTray_ButtonNumber = Get_SysTray_Index($sToolTipTitle)

If $iSysTray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Is True Color Finder Running?")
    Exit
Else
    $tRect = _GUICtrlToolbar_GetButtonRectEx($hSysTray_Handle, $iSysTray_ButtonNumber)
    $tPoint = _WinAPI_PointFromRect($tRect)
    $tPoint = _WinAPI_ClientToScreen($hSysTray_Handle, $tPoint)
    Local $iX, $iY
    _WinAPI_GetXYFromPoint($tPoint, $iX, $iY)
    MouseMove($iX, $iY)
EndIf

Func Get_SysTray_Index($sToolTipTitle)
    ; Find systray handle
    $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[CLASS:ToolbarWindow32; INSTANCE:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf
    ; Get systray item count
    Local $iSysTray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSysTray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf
    ; Look for wanted tooltip
    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 0 ; Not found
    Else
        Return $iSysTray_ButtonNumber ; Found
    EndIf
EndFunc

But still the same problem persists, directly the IF statement as below runs

If $iSysTray_ButtonNumber = 0 Then

MsgBox(16, "Error", "Is True Color Finder Running?")

Exit

and a message prompt is thrown as "Is True Color Finder Running?"

Can u please help me how to proceed further

Share this post


Link to post
Share on other sites
FireFox

@anks

It means that the trayicon with the tooltip you have specified can not be found. Have you changed the variable to set a tooltip you have?

Please apply and tell me if it works.

Edit : Changed POST LINK.

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×