Jump to content

GUIOnEventMode and TrayOnEventMode fail?


Vegar
 Share

Recommended Posts

You coded your code wrong.

Edit: I'm guessing you don't even understand what OnEvent mode is supposed to do... Try looking at the example in the helpfile. Having event mode means you can't have a loop with GUIGetMsg() or trayGetMsg(). The event automatically calls a function.

Edit 2: Assuming you have some idea of that.. make sure you use GUICtrlSetOnEvent for controls, and GUISetOnEvent for GUI events. Same for tray. Note the lack and use of CTRL in the function name.

Edited by Ichigo
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Hello

i'm trying to run with:

Opt("GUIOnEventMode", 1)

and

Opt("TrayOnEventMode",1)

why does the GUI_EVENT_..... and TRAY_EVENT..... stuff stop working?

help plz :)

Can you make a small example to duplicate the problem?
Link to comment
Share on other sites

Evrything of the "GUI_EVENT...." things work, but not the "TRAY_EVENT...."...

the thing in the script is suposed to do is when i push the Minimize button the script minimizes to tray, and when i click on the tray icon the program restores and the icon disappears... but that does not work... (evrything else works.)

Here is the code:

#NoTrayIcon
#include <GuiConstants.au3>
#include <Constants.au3>
#include <Misc.au3> 

$itimerdiff = TimerInit()
Opt("GUIOnEventMode", 1)
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)  
GuiCreate("Statistikk", 150, 200)

TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent")
$Knapp_Total_Running_time = GuiCtrlCreateButton("Total Running Time", 15, 10, 120, 30)
GUICtrlSetOnEvent (-1,"RunningTime")
$V_Museklikk = GUICtrlCreateLabel("   Venstre Museklikk", 15, 60, 120, 30)
$H_Museklikk = GUICtrlCreatelabel("   Høyre   Museklikk", 15, 80, 120, 30)

GuiSetState()

$clicksV = 0
$clicksH = 0

While 1
    
    $msg = GuiGetMsg()
  
    Select
        Case $msg = $GUI_EVENT_MINIMIZE
            GuiSetState(@SW_HIDE)
            TraySetState(1); show
            TraySetToolTip ("Click To Restore")

        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
        
    
;----------------------Venstreklikk
If _IsPressed("01", "user32.dll") Then
    while _IsPressed("01","user32.dll")
        sleep(1)
        WEnd
    $clicksV = $clicksV + 1
    GUICtrlSetData($V_Museklikk, "    Venstreklikk = " & $clicksV)
EndIf



;------------------------Høyrklikk
If _IsPressed("02", "user32.dll") Then
    while _IsPressed("02","user32.dll")
        sleep(1)
        WEnd
    $clicksH = $clicksH + 1
    GUICtrlSetData($H_Museklikk, "    Høyreklikk   = " & $clicksH)
EndIf
WEnd
;------------------------RunningTime
Func RunningTime ()
    MsgBox(0, "Running Time",  _TimerFormat(TimerDiff($itimerdiff)))
EndFunc

;------------------------TimerFormat
Func _TimerFormat($iTimerDiff)
    $iTimerDiff = Floor($iTimerDiff / 1000)

    Local $iSEC = Mod($iTimerDiff, 60)
    $iTimerDiff = Floor($iTimerDiff / 60)

    Local $iMIN = Mod($iTimerDiff, 60)
    $iTimerDiff = Floor($iTimerDiff / 60)

    Local $iHOUR = Mod($iTimerDiff, 999999999999)
    $iTimerDiff = Floor($iTimerDiff / 9999999999)

    Return StringFormat("      %.2d Hours "&@LF&"      %.2d Minutes "&@LF&"    %.2d Seconds", $iHOUR, $iMIN, $iSEC)
EndFunc

Func SpecialEvent()
    GuiSetState(@SW_Show)
    TraySetState(2); hide
EndFunc
Link to comment
Share on other sites

Thnx, got that to work.. :o

but got into another problem...

i tried to add some "TrayCreateItem"s to the script according to the help file but nothing of it will work!?

$prefsitem  = TrayCreateItem("Preferences")
TrayCreateItem("")
$aboutitem  = TrayCreateItem("About")
TrayCreateItem("")
$exititem   = TrayCreateItem("Exit")


TraySetState()

While 1

$msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $prefsitem
            Msgbox(64, "Preferences:", "OS:" & @OSVersion)
        Case $msg = $aboutitem
            Msgbox(64, "About:", "AutoIt3-Tray-sample.")
        Case $msg = $exititem
            Exit
        EndSelect

WEnd

i see the "Preferences"/"About"/"Exit" item when i right click on the icon in tray, but nothing happens when i click on eny of them :)

Edited by Vegar
Link to comment
Share on other sites

Once again, you've programming that all for not being OnEvent mode.

Use something like this: TrayItemSetOnEvent($prefsitem, '_Preferences')

And then let you _Preferences function show the msgbox that you have in the loop right now. Take out everything in your loop because right now it NOT based of OnEvent mode.

Or you could just take out the Opt('TrayOnEventmode', 1)

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

thnx :o

... got that as well to work :D

but one more thing, when i have minimized the GUI-window to TRAY, and i click (leftclick) on the trayicon to open it all the "TrayCreateItem"s pop up,... is not them just supose to pop up if you rightclick the trayicon?? :)

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...