Sign in to follow this  
Followers 0
Maffe811

Cant get tray menu items in the right order!

3 posts in this topic

When you first strart the program, you have to press Ok for the menu items to appear.

Then if you uncheck the Hide function, then click ok it disapears.

All good so far!

But then when you check it again, it adds the tray menu item to the bottom of the tray menu.

I want it to go back to where it was.

I had it working for a second, but then i messed it up and i tried to fix it back the way it was, but i dont know whats wrong.

Please do not think about the way the code is written , because its going to be incorporated into something bigger and therefore i have to keep the If _IsChecked($CheckboxHide) and the If $CheckboxHideData = true... separated.

#include-once
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;~ #NoTrayIcon
Opt("GUIOnEventMode", 1)
Opt("TrayMenuMode",1)

#Region ### START Koda GUI section ###
;Create GUI
$Gui = GUICreate("Settings", 358, 196)
;If window is closed then exit
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

;Gui content
;Disable hide function
$CheckboxHide = GUICtrlCreateCheckbox("Disable Hide function", 16, 8, 321, 41)
GUICtrlSetState(-1,$GUI_CHECKED)
;Disable Whats playing bubble
$CheckboxBubble = GUICtrlCreateCheckbox("Disable Whats playing bubble", 16, 48, 321, 41)
GUICtrlSetState(-1,$GUI_CHECKED)
;Empty disable box
$CheckboxDisabled = GUICtrlCreateCheckbox("Disabled", 16, 88, 321, 41)
GUICtrlSetState(-1,BitOr($GUI_DISABLE,$GUI_CHECKED))
;OK button
$ButtonOk = GUICtrlCreateButton("Ok", 30, 144, 129, 41, $WS_GROUP)
GUICtrlSetOnEvent(-1, "_ButtonOk")
;Cancel button
$ButtonCancel = GUICtrlCreateButton("Cancel", 198, 144, 129, 41, $WS_GROUP)
GUICtrlSetOnEvent(-1, "_Exit")
;Show gui
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Local $CheckboxHideData = true
Local $CheckboxBubbleData = true
Local $CheckboxDisabledData = true


TrayCreateItem("Next")
TrayCreateItem("Previous")
;~ TrayCreateItem("")
$Hide = TrayCreateItem("Hide",2)
$Bubble = TrayCreateItem("Bubble",3)
$Disabled = TrayCreateItem("Disabled",4)

TrayItemSetState ($Disabled,128)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

;Check for checkedness
Func _IsChecked($iControlID)
    Return BitAND(GUICtrlRead($iControlID), 1) = 1
EndFunc;==>_IsChecked

;Ok button function. Will check for checkmarks
Func _ButtonOk()
    ;Is hidden checked?
    If _IsChecked($CheckboxHide) Then
        $CheckboxHideData = true
    Else
        $CheckboxHideData = false
    EndIf
    ;Is bubble checked?
    If _IsChecked($CheckboxBubble) Then
        $CheckboxBubbleData = true
    Else
        $CheckboxBubbleData = false
    EndIf
    ;Is disabled checked?
    If _IsChecked($CheckboxDisabled) Then
        $CheckboxDisabledData = true
    Else
        $CheckboxDisabledData = false
    EndIf

    If $CheckboxHideData = true and TrayItemGetState($Hide) = 1 Then
        $Hide = TrayCreateItem("Hide")
    ElseIf $CheckboxHideData = false then
        TrayItemDelete($Hide)
    EndIf

    If $CheckboxBubbleData = true and TrayItemGetState($Bubble) = 1 Then
        $Bubble = TrayCreateItem("Bubble")
    ElseIf $CheckboxBubbleData = false then
        TrayItemDelete($Bubble)
    EndIf

    If $CheckboxDisabledData = true and TrayItemGetState($Disabled) = 1 Then
        $Disabled = TrayCreateItem("Disabled")
        TrayItemSetState ($Disabled,128)
    ElseIf $CheckboxDisabledData = false then
        TrayItemDelete($Disabled)
    EndIf

    MsgBox(64, "Checked?", "Hide function is  " & $CheckboxHideData & @CRLF & "Bubble function is " & $CheckboxBubbleData & @CRLF &  "Disabled function is " & $CheckboxDisabledData & @CRLF)

    ConsoleWrite("Hide function is  " & $CheckboxHideData & @CRLF & "Bubble function is " & $CheckboxBubbleData & @CRLF &  "Disabled function is " & $CheckboxDisabledData & @CRLF)
EndFunc;==>_ButtonOk

;Exit function. Both clicking the cancel button and closing the gui will use the _Exit function!
Func _Exit()
    Exit
EndFunc;==>_Exit

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites



Maffe811,

You need to use the menuentry parameter in your TrayCreateItem calls - that allows you to define the placing of the item within the menu. :huh2:

This gives you the basic idea - look for the <<<<<<<<< lines: :alien:

#include-once
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;~ #NoTrayIcon
Opt("GUIOnEventMode", 1)
Opt("TrayMenuMode",1)

#Region ### START Koda GUI section ###
;Create GUI
$Gui = GUICreate("Settings", 358, 196)
;If window is closed then exit
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

;Gui content
;Disable hide function
$CheckboxHide = GUICtrlCreateCheckbox("Disable Hide function", 16, 8, 321, 41)
GUICtrlSetState(-1,$GUI_CHECKED)
;Disable Whats playing bubble
$CheckboxBubble = GUICtrlCreateCheckbox("Disable Whats playing bubble", 16, 48, 321, 41)
GUICtrlSetState(-1,$GUI_CHECKED)
;Empty disable box
$CheckboxDisabled = GUICtrlCreateCheckbox("Disabled", 16, 88, 321, 41)
GUICtrlSetState(-1,BitOr($GUI_DISABLE,$GUI_CHECKED))
;OK button
$ButtonOk = GUICtrlCreateButton("Ok", 30, 144, 129, 41, $WS_GROUP)
GUICtrlSetOnEvent(-1, "_ButtonOk")
;Cancel button
$ButtonCancel = GUICtrlCreateButton("Cancel", 198, 144, 129, 41, $WS_GROUP)
GUICtrlSetOnEvent(-1, "_Exit")
;Show gui
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Local $CheckboxHideData = true
Local $CheckboxBubbleData = true
Local $CheckboxDisabledData = true


TrayCreateItem("Next")
TrayCreateItem("Previous")
;~ TrayCreateItem("")
$Hide = TrayCreateItem("Hide",2)
$Bubble = TrayCreateItem("Bubble",3)
$Disabled = TrayCreateItem("Disabled",4)

TrayItemSetState ($Disabled,128)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

;Check for checkedness
Func _IsChecked($iControlID)
    Return BitAND(GUICtrlRead($iControlID), 1) = 1
EndFunc;==>_IsChecked

;Ok button function. Will check for checkmarks
Func _ButtonOk()
    ;Is hidden checked?
    If _IsChecked($CheckboxHide) Then
        $CheckboxHideData = true
    Else
        $CheckboxHideData = false
    EndIf
    ;Is bubble checked?
    If _IsChecked($CheckboxBubble) Then
        $CheckboxBubbleData = true
    Else
        $CheckboxBubbleData = false
    EndIf
    ;Is disabled checked?
    If _IsChecked($CheckboxDisabled) Then
        $CheckboxDisabledData = true
    Else
        $CheckboxDisabledData = false
    EndIf

    If $CheckboxHideData = true and TrayItemGetState($Hide) = 1 Then
        $Hide = TrayCreateItem("Hide", -1, 2) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ElseIf $CheckboxHideData = false then
        TrayItemDelete($Hide)
    EndIf

    If $CheckboxBubbleData = true and TrayItemGetState($Bubble) = 1 Then
        $Bubble = TrayCreateItem("Bubble", -1, 3) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ElseIf $CheckboxBubbleData = false then
        TrayItemDelete($Bubble)
    EndIf

    If $CheckboxDisabledData = true and TrayItemGetState($Disabled) = 1 Then
        $Disabled = TrayCreateItem("Disabled")
        TrayItemSetState ($Disabled,128)
    ElseIf $CheckboxDisabledData = false then
        TrayItemDelete($Disabled)
    EndIf

    MsgBox(64, "Checked?", "Hide function is  " & $CheckboxHideData & @CRLF & "Bubble function is " & $CheckboxBubbleData & @CRLF &  "Disabled function is " & $CheckboxDisabledData & @CRLF)

    ConsoleWrite("Hide function is  " & $CheckboxHideData & @CRLF & "Bubble function is " & $CheckboxBubbleData & @CRLF &  "Disabled function is " & $CheckboxDisabledData & @CRLF)
EndFunc;==>_ButtonOk

;Exit function. Both clicking the cancel button and closing the gui will use the _Exit function!
Func _Exit()
    Exit
EndFunc;==>_Exit

But you will need to do some calulations to make sure you adjust the position depending on the number of displayed items - forexample if "Hide" is hidden, you need "Bubble" to display as item 2, not 3. :ph34r:

I hope this helps. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

This helps alot!

I now know what i did wrong!

Instead of:

$Hide = TrayCreateItem("Hide",2)
$Bubble = TrayCreateItem("Bubble",3)
$Disabled = TrayCreateItem("Disabled",4)
Then:

$Hide = TrayCreateItem("Hide",-1,2)
$Bubble = TrayCreateItem("Bubble",-1,3)
$Disabled = TrayCreateItem("Disabled",-1,4)
Or something like that!

Atleast now i know where i went wrong :huh2:

Thanks!


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

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  
Followers 0