Jump to content
Sign in to follow this  
t2d2c2

Tray menu don't wokring

Recommended Posts

t2d2c2

#include <Constants.au3>
#include <GUIConstants.au3>
#include <WinAPI.au3>

Opt('GUIOnEventMode', 1)
Opt('TrayOnEventMode', 1)

Opt("TrayMenuMode",1)
TraySetClick(8)
$exititem = TrayCreateItem("Exit")

Global Const $IDANI_OPEN = 1
Global Const $IDANI_CAPTION = 3

Global $hGUI = GUICreate('Test', 200, 200)
Global $fMinimized = False
Global $hTray = ControlGetHandle('[CLASS:Shell_TrayWnd]', '', 'TrayNotifyWnd1')

TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, '_Restore')
; TraySetClick(16)

GUISetOnEvent($GUI_EVENT_CLOSE, '_Minimize')

GUISetState()
While 1
    Switch TrayGetMsg()
        Case $exititem
            Exit
    EndSwitch
WEnd

Func _Minimize()
    Local $tRcFrom , $tRcTo
    
    If Not $fMinimized Then
        $tRcFrom = _WinAPI_GetWindowRect($hGUI)
        $tRcTo = _WinAPI_GetWindowRect($hTray)
        _WinAPI_DrawAnimatedRects($hGUI, $IDANI_CAPTION, DllStructGetPtr($tRcFrom), DllStructGetPtr($tRcTo))
        GUISetState(@SW_HIDE)
        $fMinimized = True
    EndIf
EndFunc

Func _Restore()
    If $fMinimized Then
        $tRcFrom = _WinAPI_GetWindowRect($hTray)
        $tRcTo = _WinAPI_GetWindowRect($hGUI)
        _WinAPI_DrawAnimatedRects($hGUI, $IDANI_CAPTION, DllStructGetPtr($tRcFrom), DllStructGetPtr($tRcTo))
        GUISetState(@SW_SHOW)
        $fMinimized = False
    EndIf
EndFunc

Func _WinAPI_DrawAnimatedRects($hWnd, $iAnim, $pRectFrom, $pRectTo)
    Local $aResult
    
    $aResult = DllCall('user32.dll', 'int', 'DrawAnimatedRects', 'hwnd', $hWnd, 'int', $iAnim, 'ptr', $pRectFrom, 'ptr', $pRectTo)
    If @error Then Return SetError(1, 0, 0)
    Return $aResult[0]
EndFunc

This is my code, when click (x) button on GUI --> HIDE GUI

When left click on trayicon --> SHOW GUI

When right click on trayicon --> show tray menu --> BUT click on tray menu item --> don't working

Help me fixed it

Share this post


Link to post
Share on other sites
JLogan3o13

t2d2c2, please do not PM forum members asking for help. This is not a 24 hour support forum; please wait 24 hours after posting an issue to give others time to respond. Then you can bump the issue if you are still having trouble.


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
t2d2c2

still nobody view and help, sorry to bother, good luck :bye:

Share this post


Link to post
Share on other sites
dmob

You forgot: TraySetOnEvent($TRAY_EVENT_SECONDARYDOWN, 'Func') ?

Share this post


Link to post
Share on other sites
t2d2c2

You forgot: TraySetOnEvent($TRAY_EVENT_SECONDARYDOWN, 'Func') ?

 

No, right click on trayicon, show menu tray OK, but when click on item on meutray --> NOT DETECT click on item

Share this post


Link to post
Share on other sites
dmob

#include <Constants.au3>
#include <GUIConstants.au3>
#include <WinAPI.au3>

Opt('GUIOnEventMode', 1)
Opt('TrayOnEventMode', 1)

Opt("TrayMenuMode",3)
TraySetClick(8)
$exititem = TrayCreateItem("Exit")

Global Const $IDANI_OPEN = 1
Global Const $IDANI_CAPTION = 3

Global $hGUI = GUICreate('Test', 200, 200)
Global $fMinimized = False
Global $hTray = ControlGetHandle('[CLASS:Shell_TrayWnd]', '', 'TrayNotifyWnd1')

TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, '_Restore')
TraySetOnEvent($TRAY_EVENT_SECONDARYDOWN, '_Exit') ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< add this
; TraySetClick(16)

GUISetOnEvent($GUI_EVENT_CLOSE, '_Minimize')

GUISetState()
While 1
    Switch TrayGetMsg()
        Case $exititem
            _Exit()
    EndSwitch
WEnd

Func _Exit()
    Exit
EndFunc

Func _Minimize()
    Local $tRcFrom , $tRcTo

    If Not $fMinimized Then
        $tRcFrom = _WinAPI_GetWindowRect($hGUI)
        $tRcTo = _WinAPI_GetWindowRect($hTray)
        _WinAPI_DrawAnimatedRects($hGUI, $IDANI_CAPTION, DllStructGetPtr($tRcFrom), DllStructGetPtr($tRcTo))
        GUISetState(@SW_HIDE)
        $fMinimized = True
    EndIf
EndFunc

Func _Restore()
    If $fMinimized Then
        $tRcFrom = _WinAPI_GetWindowRect($hTray)
        $tRcTo = _WinAPI_GetWindowRect($hGUI)
        _WinAPI_DrawAnimatedRects($hGUI, $IDANI_CAPTION, DllStructGetPtr($tRcFrom), DllStructGetPtr($tRcTo))
        GUISetState(@SW_SHOW)
        $fMinimized = False
    EndIf
EndFunc

Func _WinAPI_DrawAnimatedRects($hWnd, $iAnim, $pRectFrom, $pRectTo)
    Local $aResult

    $aResult = DllCall('user32.dll', 'int', 'DrawAnimatedRects', 'hwnd', $hWnd, 'int', $iAnim, 'ptr', $pRectFrom, 'ptr', $pRectTo)
    If @error Then Return SetError(1, 0, 0)
    Return $aResult[0]
EndFunc

Share this post


Link to post
Share on other sites
t2d2c2
#include <Constants.au3>
#include <GUIConstants.au3>
#include <WinAPI.au3>

Opt('GUIOnEventMode', 1)
Opt('TrayOnEventMode', 1)

Opt("TrayMenuMode",3)
TraySetClick(8)
$exititem = TrayCreateItem("Exit")

Global Const $IDANI_OPEN = 1
Global Const $IDANI_CAPTION = 3

Global $hGUI = GUICreate('Test', 200, 200)
Global $fMinimized = False
Global $hTray = ControlGetHandle('[CLASS:Shell_TrayWnd]', '', 'TrayNotifyWnd1')

TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, '_Restore')
TraySetOnEvent($TRAY_EVENT_SECONDARYDOWN, '_Exit') ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< add this
; TraySetClick(16)

GUISetOnEvent($GUI_EVENT_CLOSE, '_Minimize')

GUISetState()
While 1
    Switch TrayGetMsg()
        Case $exititem
            _Exit()
    EndSwitch
WEnd

Func _Exit()
    Exit
EndFunc

Func _Minimize()
    Local $tRcFrom , $tRcTo

    If Not $fMinimized Then
        $tRcFrom = _WinAPI_GetWindowRect($hGUI)
        $tRcTo = _WinAPI_GetWindowRect($hTray)
        _WinAPI_DrawAnimatedRects($hGUI, $IDANI_CAPTION, DllStructGetPtr($tRcFrom), DllStructGetPtr($tRcTo))
        GUISetState(@SW_HIDE)
        $fMinimized = True
    EndIf
EndFunc

Func _Restore()
    If $fMinimized Then
        $tRcFrom = _WinAPI_GetWindowRect($hTray)
        $tRcTo = _WinAPI_GetWindowRect($hGUI)
        _WinAPI_DrawAnimatedRects($hGUI, $IDANI_CAPTION, DllStructGetPtr($tRcFrom), DllStructGetPtr($tRcTo))
        GUISetState(@SW_SHOW)
        $fMinimized = False
    EndIf
EndFunc

Func _WinAPI_DrawAnimatedRects($hWnd, $iAnim, $pRectFrom, $pRectTo)
    Local $aResult

    $aResult = DllCall('user32.dll', 'int', 'DrawAnimatedRects', 'hwnd', $hWnd, 'int', $iAnim, 'ptr', $pRectFrom, 'ptr', $pRectTo)
    If @error Then Return SetError(1, 0, 0)
    Return $aResult[0]
EndFunc

 

No, now when right click on menutray, and not click "Exit" item, but GUI is closed

Share this post


Link to post
Share on other sites
Jos

Try:

TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, '_Restore')
;~ TraySetOnEvent($TRAY_EVENT_SECONDARYDOWN, '_Exit') ;< remove
TrayItemSetOnEvent($exititem, '_Exit') ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< add this

Jos

  • Like 1

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
t2d2c2

Try:

TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, '_Restore')
;~ TraySetOnEvent($TRAY_EVENT_SECONDARYDOWN, '_Exit') ;< remove
TrayItemSetOnEvent($exititem, '_Exit') ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< add this

Jos

 

Oh oh, it's wokring, thank you very much :thumbsup::graduated::guitar:

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  

×