Jump to content

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


Guy_
 Share

Recommended Posts

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_
Link to comment
Share on other sites

  • 2 years later...

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_
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

×
×
  • Create New...