Sign in to follow this  
Followers 0
adipose

Windows 10 clicking on tray icons

2 posts in this topic

I have been using code below for years in Windows 7 and 8, but it no longer works in Windows 10.  I found that if I have the keyboard icon showing (if you have alternate keyboards in language options), it actually clicks on it, opening the "switch keyboard" dialog.  However, if I disable the additional keyboards (which shows no icon for keyboards), it simply doesn't click at all.  Something must have changed in the api.  It appears to find the icon/handle, but it doesn't know where to click.

The keyboard tray icon always appears to the far right, which appears to be where the code below clicks.

 

Func _SysTray_ClickItem($iTitle, $iButton = "left", $iClick = 1, $sMove = False, $iSpeed = 1)
    Local $hToolbar, $iButCount, $aRect, $hButton, $cID, $i

    $hToolbar = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]")
    If @error Then
        Return SetError(1, 0, 0)
    EndIf

    $iButCount = _GUICtrlToolbar_ButtonCount($hToolbar)
    If $iButCount = 0 Then
        Return SetError(1, 0, 0)
    EndIf

    $hButton = ControlGetHandle("[Class:Shell_TrayWnd]", "", "Button2")
    If $hButton <> "" Then ControlClick("[Class:Shell_TrayWnd]", "", "Button2")

    For $i = 0 To $iButCount - 1
        $cID = _GUICtrlToolbar_IndexToCommand($hToolBar, $i)
        If StringInStr(_GUICtrlToolbar_GetButtonText($hToolBar, $cID), $iTitle) Then
            _GUICtrlToolbar_ClickButton($hToolbar, $cID, $iButton, $sMove, $iClick, $iSpeed)
            Return 1
        EndIf
    Next
    Return SetError(1, 0, 0)
EndFunc

 

Share this post


Link to post
Share on other sites



I solved the problem.  To access the tray, it is now "Instance:2" instead of "Instance:1" in windows 10.  To access the expansion menu, it is now Button4 instead of Button2.  Fixed code below.

Func _SysTray_ClickItem($iTitle, $iButton = "left", $iClick = 1, $sMove = False, $iSpeed = 1)
    Local $hToolbar, $iButCount, $aRect, $hButton, $cID, $i

    $hToolbar = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:2]")
    If @error Then
        Return SetError(1, 0, 0)
    EndIf

    $iButCount = _GUICtrlToolbar_ButtonCount($hToolbar)
    If $iButCount = 0 Then
        Return SetError(1, 0, 0)
    EndIf

    $hButton = ControlGetHandle("[Class:Shell_TrayWnd]", "", "Button4")
    If $hButton <> "" Then ControlClick("[Class:Shell_TrayWnd]", "", "Button4")

    For $i = 0 To $iButCount - 1
        $cID = _GUICtrlToolbar_IndexToCommand($hToolBar, $i)
        If StringInStr(_GUICtrlToolbar_GetButtonText($hToolBar, $cID), $iTitle) Then
            _GUICtrlToolbar_ClickButton($hToolbar, $cID, $iButton, $sMove, $iClick, $iSpeed)
            Return 1
        EndIf
    Next
    Return SetError(1, 0, 0)
EndFunc

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  
Followers 0