Jump to content

Tray menu don't wokring


Go to solution Solved by Jos,

Recommended Posts

#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

Link to post
Share on other sites
  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to post
Share on other sites

#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

Link to post
Share on other sites
#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

Link to post
Share on other sites
  • Developers
  • Solution

Try:

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

Jos

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

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...