Sign in to follow this  
Followers 0
Guy_

How to combine TrayMenu & window detection code? (+FastStone img viewer goodie)

2 posts in this topic

#1 ·  Posted (edited)

Included is a working piece of code to enlarge the handy Move / Copy dialog windows in FastStone Image Viewer, and default to the Favorites tab :)

I am usually using a main program with hotkeys.

Therefore the While 1 ... WEnd loop.

I only recently made the beginning of a TrayMenu, but I have not come across how to ideally incorporate this with the While 1 ... loop yet...

If I only include _exampleTrayMenu() in the loop, that works.

If I only include the FastStone test without _exampleTrayMenu(), that works.

If I include both in the loop, like in the example, the FastStone code doesn't enlarge the window and the TrayMenu often jumps into Pause / flashing.

1) Where to put _exampleTrayMenu() code so all combines...?

2) How to most efficiently combine multiple window detection cases in the future?

3) ...or can you run more than one AutoIt .exe and would you advise that?

For me too, it would be clearer if I had all window detection code and small stuff in a 2nd .exe.

 

#include <MsgBoxConstants.au3>
#include <TrayConstants.au3>

Opt("WinTitleMatchMode", 2)


; MAIN program loop

While 1

    If WinActive("[CLASS:TCopyMoveFolder]") Then

        _FastStoneImgViewer()

    Else

        _exampleTrayMenu()

        Sleep(100)

    EndIf

WEnd


; Detect opening of both Copy & Move windows in Faststone viewer, enlarge them and click 'Favorites' tab

Func _FastStoneImgViewer()

    ; if WinActive(" to Folder") (when Copy or Move window appears)
    If WinActive( "[CLASS:TCopyMoveFolder]" ) Then

        Local $hWnd = WinGetHandle("[CLASS:TCopyMoveFolder]")

        ; click once on tab 'Favorites'
        ControlClick( $hWnd, "", "[CLASS:TbsSkinPageControl; INSTANCE:1]", "left", 1, 70, 10 )

        ; enlarge window
        WinMove($hWnd, "", Default, 60, 900, 1060)

        ; move buttons down
        ; BUTTON Clear History List
        ControlMove($hWnd, "", "[CLASS:TbsSkinButton; INSTANCE:1]", Default, 990)
        ; BUTTON
        ControlMove($hWnd, "", "[CLASS:TbsSkinButton; INSTANCE:2]", Default, 990)
        ; BUTTON
        ControlMove($hWnd, "", "[CLASS:TbsSkinButton; INSTANCE:3]", Default, 990)
        ; BUTTON
        ControlMove($hWnd, "", "[CLASS:TbsSkinButton; INSTANCE:4]", Default, 990)

        ; ENLARGE the Inside Window
        ControlMove($hWnd, "", "[CLASS:TbsSkinPageControl; INSTANCE:1]", Default, Default, 862, 910)

        ; ensure focus is back to inside window and previously selected item (so 'select by keypress' will work)
        ControlFocus( $hWnd, "", "[CLASS:TListView; INSTANCE:1]" )


        WinWaitNotActive($hWnd)

    EndIf
EndFunc


; traymenu example from manual
Func _exampleTrayMenu()
    Local $iSettings = TrayCreateMenu("Settings") ; Create a tray menu sub menu with two sub items.
    Local $iDisplay = TrayCreateItem("Display", $iSettings)
    Local $iPrinter = TrayCreateItem("Printer", $iSettings)
    TrayCreateItem("") ; Create a separator line.

    Local $idAbout = TrayCreateItem("About")
    TrayCreateItem("") ; Create a separator line.

    Local $idExit = TrayCreateItem("Exit")

    TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu.

    While 1
        Switch TrayGetMsg()
            Case $idAbout ; Display a message box about the AutoIt version and installation path of the AutoIt executable.
                MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _
                        "Version: " & @AutoItVersion & @CRLF & _
                        "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) ; Find the folder of a full path.

            Case $iDisplay, $iPrinter
                MsgBox($MB_SYSTEMMODAL, "", "A sub menu item was selected from the tray menu.")

            Case $idExit ; Exit the loop.
                ExitLoop
        EndSwitch
    WEnd
EndFunc
Edited by Guy_

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Update for v6.x (tested with v6.2).

http://www.faststone.org/FSViewerDownload.htm

This should simply work. I'm not asking questions about it (in this thread).

Open the Copy or Move dialog and it should automatically enlarge. Very handy if you are using tons of destination folders.

I made this for a 1920 x 1200 screen.

(I guess you can probably risk deleting the If/EndIf lines inside the function.)

 

; MAIN program loop

While 1

    ; Detect opening of both Copy & Move windows in Faststone viewer
    If WinActive("[CLASS:TCopyMoveFolder.UnicodeClass]") Then _FastStoneImgViewer()
    
    Sleep(50)

WEnd


; enlarge Copy/Move windows and click 'Favorites' tab

Func _FastStoneImgViewer()

    ; when Copy or Move window is active
    If WinActive( "[CLASS:TCopyMoveFolder.UnicodeClass]" ) Then

        Local $hWnd = WinGetHandle("[CLASS:TCopyMoveFolder.UnicodeClass]")

        ; click once on tab 'Favorites'
        ControlClick( $hWnd, "", "[CLASS:TPageControl; INSTANCE:1]", "left", 1, 70, 10 )

        ; enlarge window
        WinMove($hWnd, "", Default, 60, 900, 1060)

        ; move 4 buttons down
        ; BUTTON Clear History List
        ControlMove($hWnd, "", "[CLASS:TButton; INSTANCE:1]", Default, 990)
        ; BUTTON
        ControlMove($hWnd, "", "[CLASS:TButton; INSTANCE:2]", Default, 990)
        ; BUTTON
        ControlMove($hWnd, "", "[CLASS:TButton; INSTANCE:3]", Default, 990)
        ; BUTTON
        ControlMove($hWnd, "", "[CLASS:TButton; INSTANCE:4]", Default, 990)

        ; ENLARGE the Inside Window
        ControlMove($hWnd, "", "[CLASS:TPageControl; INSTANCE:1]", Default, Default, 862, 910)

        ; ensure focus is back to inside window and previously selected item (so 'select by keypress' will work)
        ControlFocus( $hWnd, "", "[CLASS:TTntListView.UnicodeClass; INSTANCE:1]" )


        WinWaitNotActive($hWnd)

    EndIf

EndFunc

 

Edited by Guy_

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

  • Similar Content

    • Guy_
      By Guy_
      I'd be happy with help, even for problem (1) alone, so don't be overwhelmed...
      Rusty and frustrated with some weird stuff in my program for well over 2 years, I've finally made a reproducer... (I'm using v3.3.14.1 here)
      In this forum, I picked up some code to detect a Mouse Right-click (see URL below). I have no idea if that code is solid or dodgy...
      In my program I test for the combo of Shift + Right-click, which will then automatically copy the URL of an underlying html link and do stuff with it (here simply replaced with a BEEP).
      In the reproducer, when doing Shift + R-click anywhere, this should initially BEEP (if your sound is on), unless you enable the TrayMenu...
      Problems that have come up so far ...
      (1) [SOLVED with help of 3rd post] If you enable the line creating the _Example_TrayMenu(), that menu will work but my Shift + R-click feature seems sabotaged by it for some reason...?
      (2) [I pray this might be solved by (1), cause this one may be hard to get a clue on...]
      If I set everything [no TrayMenu] so I can use the Shift + R-click detection, another problem is that this feature often gets disabled somehow — usually between 5 to 120 mins. Occasionally, it still works the following morning. Still have I been unable to get a clue to what might sabotage it. It might be a specific thing me or my PC is doing, or might it be a buffer that is corrupting by the use of the detection code? (I'm pretty sure I'm also getting this without pausing/unpausing my program, but I'll retest) (there is a chance this may not happen in the reproducer and only in my full program; I'll try and test for that)
      (3) To hopefully prevent (2) — and since I usually pause the utility quite often — I hoped that at the same time correctly stopping and restarting this detection system might mostly prevent the problem, or at least make it easy for me to reboot the functionality by pausing/unpausing. I asked if I was doing that right more than a year ago, but possibly in a time that many took their holiday, so never heard back. That question (and the original detection code) is here (I guess it needs a reproducer too, and I may make that tomorrow...) : 
      If (1) could get solved, I'd be very happy and could retest for (2) a while. (3) is of course also very welcome, cause it might be the 'easy' workaround for (2), or another reason stuff might get corrupted (although I'm currently probably not pausing/unpausing the detection system, cause how I do it crashes AutoIt; see other topic).
      Thank You for having a look! 
      #Region #AutoIt3Wrapper_UseX64=n #EndRegion #include <Misc.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <TrayConstants.au3> Opt("TrayMenuMode", 3) Local $hDLL = DllOpen("user32.dll") ;~ _Example_TrayMenu() ; When enabled, the Shift + R-click detection won't work. Why? ; mouse R-click detection code from www.autoitscript.com/forum/topic/119856-detect-fast-mouse-click Global Const $HC_ACTION = 0 Global $hStub_MouseProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam") Global $hmod = _WinAPI_GetModuleHandle(0) Global $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_MouseProc), $hmod) Global $iMseDwn = 0 Func _MouseProc($nCode, $wParam, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndIf If $nCode = $HC_ACTION Then Switch $wParam Case $WM_RBUTTONDOWN $iMseDwn = 3 ; assigned code for a Mouse R-click EndSwitch EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc While 1 ; MAIN LOOP Switch $iMseDwn Case 3 ; Mouse Right was clicked MouseUp($MOUSE_CLICK_RIGHT) ; 'unclick' it $iMseDwn = 0 ; reset var If _isPressed("10", $hDLL) Then ; is Shift held down as well? _Mouse_R_click(10) ; (10 = Shift key) call BEEP Func EndIf EndSwitch Sleep(50) WEnd Func _Mouse_R_click($_modKey) ; called from MAIN LOOP if Shift was held down before R-click If $_modKey = 10 Then ;~ MsgBox(0,"", "You performed Shift + R-click") Beep(300,30) EndIf EndFunc Func _Example_TrayMenu() ; example from AutoIt Help on TrayCreateMenu Local $iSettings = TrayCreateMenu("Settings") Local $iDisplay = TrayCreateItem("Display", $iSettings) Local $iPrinter = TrayCreateItem("Printer", $iSettings) TrayCreateItem("") Local $idAbout = TrayCreateItem("About") TrayCreateItem("") Local $idExit = TrayCreateItem("Exit") TraySetState($TRAY_ICONSTATE_SHOW) While 1 Switch TrayGetMsg() Case $idAbout MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) Case $iDisplay, $iPrinter MsgBox($MB_SYSTEMMODAL, "", "A sub menu item was selected from the tray menu.") Case $idExit ExitLoop EndSwitch WEnd EndFunc  
       
    • eyalsemo1
      By eyalsemo1
      Hello all,

      2 quest:

      1. Is it possible for TrayMenu, to align the menus right to left (hebrew) ?

      2. I am using #include <TrayConstants.au3> to control the BGcolor

        can I choose to use different colors for different menus on the same TrayMenu

        I have tried different name for every set of TrayCreateMenu

        And assigning different bgcolor for every menu (under the same TrayMenu) but didn't get the result

      TNX Eyal
    • lgvlgv
      By lgvlgv
      Hi all!
      I have a problem with creating the right varibles in the switch statment and wonder if some on can help me figure out the best way to procide?
      i got the part when i create all trayitems with a "FOR" statement from an ini file working, but i fail when it comes to the switch statement.
      ini file look like this..
      [Links]
      Calulator=Calc.exe
      and so on...
       
      here is part of my script..
      it works for a few min.. then the hole application hangs (when compiled, seems to work in test mode, before i compile it?)
      is this part that seems to cose the error?
      Case Else If $Msg > 0 Then _DebugOut("While Statement - $Msg: " & $Msg) $aSearch = _ArraySearch($Linksarray, $gText, 0, 0, 0, 1, 1, 0) If @error Then Else $aSearch1 = _ArraySearch($Linksarray, $Linksarray[$aSearch][0], 0, 0, 0, 1, 1, 0) If @error Then Else _DebugOut("While Statement - $aSearch1: " & $Linksarray[$aSearch1][0]) _DebugOut("While Statement - $aSearch1: " & $Linksarray[$aSearch1][1]) ShellExecute($Linksarray[$aSearch][1], "", "", "open") EndIf EndIf EndIf here is both functions...
      Func _WinMain() _readConfigFile() Opt("TrayMenuMode", 11) Opt("GUIOnEventMode", 0) ;0=disabled, 1=OnEvent mode enabled _TrayInit() ; Main GUI Loop Local $tvHandle = 0 $iBegin = TimerInit() $LatencyUrl = IniRead($ConfigFile, "General", "LatencyUrl", "www.charger.se") $LatencyMS = IniRead($ConfigFile, "General", "LatencyMS", "500") HotKeySet("+!z", '_ShowITSupport') HotKeySet("+!x", '_ShowITSupport') While 1 $Msg = GUIGetMsg() $gText = _GetMenuText($Msg) If TimerDiff($iBegin) > 5000 Then ; Loop until 5 sec have passed _Ping($LatencyUrl, $LatencyMS) #cs Local $net_test = _IsInternetConnectedEx() ; ConsoleWrite("$net_test: " & $net_test & @CRLF) If $net_test = 1 Then Local $net_test2 = __GetConnectedAdapterIPMAC() If StringInStr($net_test2, "Wireless") Or StringInStr($net_test2, "Wired") Then EndIf Else ConsoleWrite("$net_test2? " & __GetConnectedAdapterIPMAC() & @CRLF) EndIf #ce ; ConsoleWrite("Counter: " & $iBegin & @CRLF) $iBegin = TimerInit() EndIf Switch $Msg Case $ToggleLogonUser _DebugOut("While Statement - $ToggleLogonUser: " & $gText) _ToggleLogonUser() Case $TrayTS _DebugOut("While Statement - $TrayTS: " & $gText) _DebugOut(@ScriptDir & "TeamViewerQS_sv-idcnnz7xxq.exe" & @CRLF) FileInstall("Res\TeamViewerQS_sv-idcnnz7xxq.exe", @ScriptDir & "\TeamViewerQS_sv-idcnnz7xxq.exe", 0) ShellExecute("TeamViewerQS_sv-idcnnz7xxq.exe", "", @ScriptDir, 'open') ; Sleep(10000) Case $ResetInternet _DebugOut("While Statement - $ResetInternet: " & $gText) $tmpNessage = MsgBox(20, "Warning", "You are about to do a complete Network reset!") If $tmpNessage = 6 Then _DebugOut("While Statement - $ResetInternet: MsgBox, Returns: " & $tmpNessage) Else _DebugOut("While Statement - $ResetInternet: MsgBox, Returns: " & $tmpNessage) EndIf Case $TrayExit _DebugOut("While Statement - $TrayExit: " & $gText) _TrayIconDelete($nTrayIcon1) ExitLoop Case Else #cs If $Msg > 0 Then _DebugOut("While Statement - $Msg: " & $Msg) $aSearch = _ArraySearch($Linksarray, $gText, 0, 0, 0, 1, 1, 0) If @error Then Else $aSearch1 = _ArraySearch($Linksarray, $Linksarray[$aSearch][0], 0, 0, 0, 1, 1, 0) If @error Then Else _DebugOut("While Statement - $aSearch1: " & $Linksarray[$aSearch1][0]) _DebugOut("While Statement - $aSearch1: " & $Linksarray[$aSearch1][1]) ShellExecute($Linksarray[$aSearch][1], "", "", "open") EndIf EndIf EndIf #ce EndSwitch Sleep(10) WEnd _TrayIconDelete($nTrayIcon1) EndFunc ;==>_WinMain Func _TrayInit() Opt('TrayMenuMode', 3) ; Default tray menu items (Script Paused/Exit) will not be shown. Opt('TrayAutoPause', 0) ; Script will not be paused when clicking the tray icon. ;Opt("TrayOnEventMode", 1) Opt('MustDeclareVars', 0) ; *** Create the tray icon *** ;Func _TrayIconCreate($sToolTip = "", $sIconFile = @AutoItExe, $nIconID = 0, $sCallback = "", $nMsg = 0, $hIcon = 0) ;TraySetIcon(@ScriptFullPath, "201") $nTrayIcon1 = _TrayIconCreate("Datornamn: " & @ComputerName & @CRLF & "IPAdress: " & @IPAddress1 & " ," & @IPAddress2, @ScriptFullPath, -1) _TrayIconSetClick(-1, 16) _TrayIconSetState() ; Show the tray icon ; *** Create the tray context menu *** Local $iIndex = _ArraySearch($GeneralArray, "Kund", 0, 0, 0, 1, 1, 0) $TrayMenuname = "ChaQ - " & $GeneralArray[$iIndex][1] $nTrayMenu1 = _TrayCreateContextMenu() ; is the same like _TrayCreateContextMenu(-1) or _TrayCreateContextMenu($nTrayIcon1) $nSideItem3 = _CreateSideMenu($nTrayMenu1) _SetSideMenuText($nSideItem3, $TrayMenuname) _SetSideMenuColor($nSideItem3, 0x00FFFF) ; yellow; default color - white _SetSideMenuBkColor($nSideItem3, 0x802222) ; bottom start color - dark blue _SetSideMenuBkGradColor($nSideItem3, 0x4477AA) ; top end color - orange _SetSideMenuImage($nSideItem3, "shell32.dll", 309, True) $TrayCase = _TrayCreateItem("SupportCenter, Add a Case") _TrayCreateItem("") _TrayItemSetIcon($TrayCase, @ScriptFullPath, -7) $TrayTS = _TrayCreateItem("Teamviwer") _TrayCreateItem("") _TrayItemSetIcon($TrayTS, @ScriptFullPath, -9) $MenuLinks = _TrayCreateMenu("Links") _TrayCreateItem("") _TrayItemSetIcon($MenuLinks, "shell32.dll", -44) $MenuTools = _TrayCreateMenu("Program") _TrayCreateItem("") _TrayItemSetIcon($MenuTools, "", 0) $chargeitem = _TrayCreateMenu("Tools") $chargeitem1 = _TrayCreateMenu("Settings", $chargeitem) _TrayCreateItem("") $TrayExit = _TrayCreateItem("Exit") _TrayItemSetIcon($TrayCase, @ScriptFullPath, -7) _TrayItemSetIcon($MenuLinks, "shell32.dll", -318) _TrayItemSetSelIcon($MenuLinks, "shell32.dll", -44) _TrayItemSetIcon($MenuTools, "shell32.dll", -20) _TrayItemSetSelIcon($MenuTools, "shell32.dll", -20) _TrayItemSetIcon($chargeitem, @ScriptFullPath, -11) _TrayItemSetSelIcon($chargeitem, @ScriptFullPath, -11) _TrayItemSetIcon($chargeitem1, @ScriptFullPath, -11) _TrayItemSetSelIcon($chargeitem1, @ScriptFullPath, -11) _TrayItemSetIcon($TrayHelp, "mstsc_101.ico", 0) _TrayItemSetIcon($TrayTS, @ScriptFullPath, -9) _TrayItemSetIcon($TrayExit, "shell32.dll", -28) ; *** Sub menu items *** For $x = 1 To $Linksarray[0][0] _DebugOut("$Linksarray " & $Linksarray[$x][0]) If StringInStr($Linksarray[$x][1], "http") Then $Tray_Item[$x] = _TrayCreateItem($Linksarray[$x][0], $MenuLinks) _TrayItemSetIcon($Tray_Item[$x], "shell32.dll", -14) Else $Tray_Item[$x] = _TrayCreateItem($Linksarray[$x][0], $MenuTools) _TrayItemSetIcon($Tray_Item[$x], $Linksarray[$x][1], "") EndIf Next $EnableBit = _TrayCreateItem("Enable (BIT/WSUS)", $chargeitem) $DisableBit = _TrayCreateItem("Disable (BIT/WSUS)", $chargeitem) $ResetInternet = _TrayCreateItem("Reset Internet Connection", $chargeitem) $ToggleLogonUser = _TrayCreateItem("Toggle Username/logon screen", $chargeitem) _TrayItemSetIcon($TrayTSSite, "shell32.dll", -14) _TrayItemSetIcon($TraySupportSite, "shell32.dll", -14) _TrayItemSetIcon($TraySupportSite1, "shell32.dll", -14) _TrayItemSetIcon($DisableBit, "shell32.dll", -275) _TrayItemSetIcon($EnableBit, "shell32.dll", -276) _TrayItemSetIcon($ResetInternet, @ScriptFullPath, -12) _TrayItemSetIcon($ToggleLogonUser, "regedit.exe", -1) GUICtrlSetState($chargeitem, $GUI_DISABLE) GUICtrlSetState($EnableBit, $GUI_DISABLE) GUICtrlSetState($DisableBit, $GUI_DISABLE) GUICtrlSetState($ResetInternet, $GUI_DISABLE) EndFunc ;==>_TrayInit