Jump to content

Multi-monitor and Auto-hide taskbar interferes with script


ckovoor
 Share

Recommended Posts

This is for Melba23, as the script is originally his.

Sir, I modified a version of your script I found at:

'?do=embed' frameborder='0' data-embedContent>>

and also:

'?do=embed' frameborder='0' data-embedContent>>

Thank you for this marvellous script. My version below opens the right-click options menu on the Input Director tray icon and toggles the switch which enables/disables ID macros. It also assigns a hotkey to the function so that further toggles can be activated with the hotkey. (Input Director is a program which allows control over several networked pc's with a single mouse and keyboard.)

Now the script works flawlessly on a single-monitor system or a single notebook screen, even with the Auto-hide option on the Taskbar activated and the Taskbar hidden. However, when I tried it out on a multi-monitor system with Auto-hide on the Taskbar active and Taskbar hidden, it started giving problems. Here is the script (ToggleIDMacros.au3):

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Constants.au3>
;
; AutoIt Version: 3.0
; Language:       English
; Platform:       Win9x/NT
; Author:         Melba23 (modified by Chakko Kovoor)
; Script Version: 1.1 (11/Sep/14)
; Script Function:
;   toggles enable/disable macros (switch)on Input Director menu brought up when you right-click on its tray icon, with confirmation of action
;   first run of script toggles macro switch, and sets up hotkey F4 for further toggles of switch
;   for those with multi-monitor setups, if you experience problems, then activating (by removing the leading ;) the lines marked "for multi-monitor setups" may help
;

#include <WindowsConstants.au3>
#include <GUIToolbar.au3>
#include <WinAPI.au3>
#Include <GuiMenu.au3>
#include <GuiButton.au3>

Call ( "Togglemacro" )

HotKeySet ("{F4}","Togglemacro")    ; <<<<<<<<< set your hotkey
While 1
    Sleep (1000)
WEnd

Func Togglemacro()

Opt("WinTitleMatchMode", 2)
Global $hSysTray_Handle, $iSystray_ButtonNumber, $sItemName
Global $sToolTipTitle = "Input Director (Master)" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here

;Local $aPos = MouseGetPos()        ; <<<<<<<<< for multi-monitor setups
;MouseMove(100, @DesktopHeight, 0)  ; <<<<<<<<< for multi-monitor setups
$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = -1 Then
    MsgBox(16, "Error", "Icon not found in system tray")
    Exit
Else
    Sleep(250)
    ; right click and select fourth menu item (up)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
    Sleep(250)
    Send("{UP 4}")
    $sItemName = GetPopUpSelText() ; This will read the currently selected item <<<<<<<<<<<<<<<<<<<<<<<<<<<<
    If $sItemName = "Enable Macros" Then
        Send("{ENTER}")
        ;MouseMove($aPos[0], $aPos[1], 0)   ; <<<<<<<<< for multi-monitor setups
        SplashTextOn ( "", "Macros ENABLED" , 160 , 40, -1, -1, 1,"",10, 600 )
        SoundPlay(@WindowsDir & "\media\chimes.wav", 0)
        Sleep (2500)
        SplashOff ()
     Elseif $sItemName = "Disable Macros" Then
        Send("{ENTER}")
        ;MouseMove($aPos[0], $aPos[1], 0)   ; <<<<<<<<< for multi-monitor setups
        SplashTextOn ( "", "Macros DISABLED" , 160 , 40, -1, -1, 1,"",10, 600 )
        SoundPlay(@WindowsDir & "\media\chimes.wav", 0)
        Sleep (2500)
        SplashOff ()
     Else
        Send("{ESC}")
        ;MouseMove($aPos[0], $aPos[1], 0)   ; <<<<<<<<< for multi-monitor setups
        SplashTextOn ( "", "Option Not Found!" , 160 , 40, -1, -1, 1,"",10, 600 )
        SoundPlay(@WindowsDir & "\media\chord.wav", 0)
        Sleep (2500)
        SplashOff ()
    EndIf
EndIf

EndFunc

;............

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
        ; check overflow section of systray
        Return Get_OverflowSystray_Index($sToolTipTitle)
    EndIf

    ; Look for wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return Get_OverflowSystray_Index($sToolTipTitle)
     Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc


Func Get_OverflowSystray_Index($sToolTipTitle)

   $hSysTray_Handle = ControlGetHandle('[Class:NotifyIconOverflowWindow]', '', '[Class:ToolbarWindow32;Instance:1]')
   $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
   If $iSystray_ButCount = 0 Then
      MsgBox(16, "Error", "No items found in system tray")
      Exit
   EndIf

   For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
     If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
   Next
   If $iSystray_ButtonNumber < $iSystray_ButCount Then
      $hSysTray_OverflowButton = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[CLASS:Button; INSTANCE:1]')
      _GUICtrlButton_Click($hSysTray_OverflowButton)
      Return $iSystray_ButtonNumber ; Found
   Else
      Return -1
   EndIf

EndFunc


Func GetPopUpSelText()

    Local $aPopUp_List = _WinAPI_EnumWindowsPopup()
    Local $hWnd = $aPopUp_List[1][0]
    Local $sClass = $aPopUp_List[1][1]
    If $sClass = "#32768" Then ; This is a "standard" Windows API popup menu
        $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $iCount = _GUICtrlMenu_GetItemCount($hMenu)
            For $j = 0 To $iCount - 1
                If _GUICtrlMenu_GetItemHighlighted($hMenu, $j) Then
                    Return _GUICtrlMenu_GetItemText($hMenu, $j)
                EndIf
            Next
        EndIf
    EndIf
    Return ""

EndFunc

With a multi-monitor setup, the script starts misbehaving at line 47 when _GUICtrlToolbar_ClickButton fails to right-click on the tray icon, but instead right-clicks close by but on an adjacent monitor in the system, bringing up the local right-click context menu, and then Func GetPopUpSelText starts looking at irrelevant options. I found I could prevent this behaviour only by first moving the mouse pointer down to the lower boundary of the main monitor, thus un-hiding the taskbar, and only then invoking _GUICtrlToolbar_ClickButton. These mouse activities appear at lines 37, 38, 53, 60 and 67.

I did try altering the parameters $fMove = False/True and $iSpeed = 1/0 but it made no difference. _GUICtrlToolbar_ClickButton is able to locate the tray correctly only when the Taskbar is visible. Otherwise it clicks somewhere close to the tray, but on a monitor located adjacent to the main monitor. To me this appears to be a limitation in the function _GUICtrlToolbar_ClickButton .

Would you be able to explain why this happens on multi-monitor systems with Auto-hide on taskbar active when the Taskbar is hidden, and whether there is a neater way of solving the problem?

I should mention that my multi-monitor system has 4 video outputs and 2 Matrox dual-head-to-go units, for a total of 6 monitors, and that I am running Win7 x64. Also I am a novice at programming and relatively new to autoit.

Once again, thank you for your remarkable script. This is a great help on my system, where I use macros extensively.

Edited by ckovoor
Link to comment
Share on other sites

  • Moderators

ckovoor,

 

Would you be able to explain why this happens on multi-monitor systems with Auto-hide on taskbar active when the Taskbar is hidden

Not a clue. :wacko:

 

whether there is a neater way of solving the problem

Try this to set the taskbar state:

Global Const $ABS_NORMAL = 0
Global Const $ABS_AUTOHIDE = 1

_TaskBarSet($ABS_AUTOHIDE)

Sleep(5000)

_TaskBarSet($ABS_NORMAL)

Func _TaskBarSet($iState)

    Local Const $ABM_SETSTATE = 10
    Local $tStruct = DllStructCreate("dword;int;uint;uint;int;int;int;int;int")
    DllStructSetData($tStruct, 1, DllStructGetSize($tStruct))
    DllStructSetData($tStruct, 2, ControlGetHandle("Start", "", "Shell_TrayWnd"))
    DllStructSetData($tStruct, 9, $iState)

    $aRet = DllCall("shell32.dll", "int", "SHAppBarMessage", "int", $ABM_SETSTATE, "ptr", DllStructGetPtr($tStruct))
    If Not @error And $aRet[0] Then
        Return $aRet[0]
    EndIf
    Return SetError(1, 0, 0)

EndFunc   ;==>_TaskBarSet
That works for me - you may have to play with the taskbar handle. ;)

Glad you found the scripts useful - flattery always helps with follow-on questions. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Melba23,

Sir, ....Thank you for taking a look at this..... :wub:

_TaskBarSet has the effect (on my systems) of un-hiding the taskbar permanently (it even unchecks the auto-hide taskbar option in Taskbar and Start Menu Properties, until the user toggles that option again) and so, since the taskbar becomes visible, _GUICtrlToolbar_ClickButton starts operating normally again. And as long as the Taskbar remains visible/unhidden, the script works. But when I go and re-enable Auto-hide on the Taskbar and Start Menu Properties menu, the misbehaviour resurfaces. My problem is that I do need Auto-hide on the Taskbar to be active.

For the time being, my clumsy  :(  work-around does the job of temporarily un-hiding the taskbar.

Thank you for your time and patience.    :ILA3: and your scripts!

Warmest regards,

ckovoor.

Edited by ckovoor
Link to comment
Share on other sites

I would assume that there is an issue with this function:

Func _GUICtrlToolbar_ClickButton($hWnd, $iCommandID, $sButton = "left", $bMove = False, $iClicks = 1, $iSpeed = 1)
    Local $tRect = _GUICtrlToolbar_GetButtonRectEx($hWnd, $iCommandID)
    Local $tPoint = _WinAPI_PointFromRect($tRect)
    $tPoint = _WinAPI_ClientToScreen($hWnd, $tPoint)
    Local $iX, $iY
    _WinAPI_GetXYFromPoint($tPoint, $iX, $iY)
    Local $iMode = Opt("MouseCoordMode", 1)
    If Not $bMove Then
        Local $aPos = MouseGetPos()
        _WinAPI_ShowCursor(False)
        MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
        MouseMove($aPos[0], $aPos[1], 0)
        _WinAPI_ShowCursor(True)
    Else
        MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
    EndIf
    Opt("MouseCoordMode", $iMode)
EndFunc   ;==>_GUICtrlToolbar_ClickButton

Comment out line 371 as an initial test just to see what happens.  Other than that, good luck. 

I bid you peace.

Edited by jaberwacky
Link to comment
Share on other sites

  • Moderators

ckovoor,

I fear I was not clear enough when describing the script I posted - I can only plead that I was supervising flying operations at the time and so not fully focused on AutoIt. :(>

The script offers you the ability to toggle the Taskbar "AutoHide" property programmatically using the _TaskBarSet function. It autohides a visible taskbar, pauses and then reshows it - it was not a "plug-in" solution for you. :)

You would need to do something like this:

- 1. You have the taskbar autohidden, which you say is required.

- 2. Your script starts and immediately you run _TaskBarSet($ABS_NORMAL) to get the Taskbar visible.

- 3. The script continues with all the icon clicking, etc that you require.

- 4. At the end of your script you run _TaskBarSet($ABS_AUTOHIDE) to reset the Taskbar to the "AutoHide" state.

That way you only keep the taskbar visible while you need it. ;)

Does that make more sense? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Melba23,

Thank you for explaining how _TaskBarSet is to be used. I was indeed just autohiding and unhiding the Taskbar :> before invoking the central Togglemacro function :D!

So I did as you prescribed, and of course, it works: _TaskBarSet programmatically unhides the Taskbar, the icon clicking then proceeds correctly, and then _TaskBarSet programmatically autohides the Taskbar again.

Unfortunately, there are two side-effects to this use of _TaskBarSet on my system, which my mouse movements do not produce:

(i) As the Taskbar advances during the unhiding, it claims that desktop area for itself alone and repels any desktop icons residing there, triggering a general re-arrangement of my desktop icons, all 40 of them. And then as the Taskbar retreats into auto-hiding, the desktop icons scurry back into their original positions. This en-masse back-and-forth sidestepping dance of icons is a little disorienting :(

(ii) If instead I have a maximized window occupying the main desktop monitor, then the advancing Taskbar squeezes that too, and when the Taskbar retreats, the window does not re-maximize but remains in its slightly diminished state.

It seems that _TaskBarSet incites the Taskbar into becoming temporarily unwilling to cohabit with either windows or icons, which mouse movement onto the Taskbar does not.

So, for the time being, I'll stick with my work-around. But thank you, Sir, for your time and patience, and for teaching more of Autoit.

ckovoor.

Edited by ckovoor
Link to comment
Share on other sites

jaberwacky,

Thank you for your interest in this.....when I commented out line 371, the clicking happened somewhere near the top left corner of the main desktop monitor, far away from the tray in the bottom right corner, and diametrically opposite to it. So unfortunately, the issue with  _GlUICtrlToolbar_ClickButton remains.

ckovoor.

Edited by ckovoor
Link to comment
Share on other sites

  • Moderators

ckovoor,

 

en-masse back-and-forth sidestepping dance of icons

I do not place my icons so close to the Taskbar area so that effect did not appear when I tested - it must have been something to see! :D

 

when the Taskbar retreats, the [maximized] window does not re-maximize but remains in its slightly diminished state

I had tested to check whether that occurred - and on my single monitor Win7 system it does not. The maximized window resets itself to full size as soon as the taskbar withdraws to its hidden state. What OS are you running? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Melba23,

Actually, now that I count, I have 93 desktop icons: 8 vertical columns of 11 each plus 5 in the 9th column. So the icons go right down to the lower edge of the desktop.

I run Win 7 x64 Home Premium, on both my single-monitor laptop and the multi-monitor desktop. I should clarify that these effects do not occur on my laptop. I am wondering whether there might be some interference from Matrox PowerDesk (desktop management software) which I am using on the multi-monitor system.

ckovoor.

Edited by ckovoor
Link to comment
Share on other sites

  • Moderators

ckovoor,

 

93 desktop icons

How on earth do you find anything among that lot? I use a small number of desktop folders (some with further internal folders) to group related icons - that makes it very easy to locate whatever I need. :)

 

I am wondering whether there might be some interference from Matrox PowerDesk (desktop management software)

I imagine that it is quite possible. What you could perhaps do is to check through all open windows to see which one (if any) is maximized and then run a RESTORE/MAXIMIZE cycle on it to reset the "correct" size. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...