Jump to content

enabling TrayMenu can sabotage other functionality?


Guy_
 Share

Recommended Posts

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

 

 

Edited by Guy_
Link to comment
Share on other sites

[SOLVED] I just updated an older thread from 2014, and there also I was already asking the question without answer...

I may simply not have a clue how to properly initiate a TrayMenu when my program has a main loop...? (the Help example is without loop)

So as another example: this thing works fine to enlarge the Copy/Move dialogs in Faststone viewer... until you enable the TrayMenu on the third line... Then the menu works, but I lose my main feature...

 

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


;~ _exampleTrayMenu()


; 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


; traymenu example from manual
Func _exampleTrayMenu()
    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

 

original:

UPDATE: now working as expected (after watching vid in next post)

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

; for TrayMenu

    $iSettings = TrayCreateMenu("Settings")
    $iDisplay = TrayCreateItem("Display", $iSettings)
    $iPrinter = TrayCreateItem("Printer", $iSettings)
    TrayCreateItem("")

    $idAbout = TrayCreateItem("About")
    TrayCreateItem("")

    $idExit = TrayCreateItem("Exit")

    TraySetState($TRAY_ICONSTATE_SHOW)


; MAIN program loop

While 1

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


    ; for TrayMenu

        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


    Sleep(50)

WEnd


Func _FastStoneImgViewer()          ; enlarge the Copy/Move windows and click 'Favorites' tab

    ; if Copy / 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...