Sign in to follow this  
Followers 0
mesale0077

tray menu

7 posts in this topic

#1 ·  Posted (edited)

hi

tray menu dont work

----------------------------------------------------

ACTIVE }

DISABLE } tray menu dont work

EXİT }

-----------------------------------------------------

Global $Paused
 If UBound(ProcessList(@ScriptName)) > 2 Then

    Exit 0
EndIf

FileInstall ( "C:\batary.mp3", @TempDir &"\batary.mp3" )




Opt("TrayMenuMode",3)

$aetitem  = TrayCreateItem("ACTIVE")

$dvbtitem   = TrayCreateItem("DISABLE")

$exititem   = TrayCreateItem("EXİT")

TraySetState()

akf()
func akf()
$s          = ""
$battery    = _BatteryQuery()
while  1
  $msgr = TrayGetMsg()
   
     Switch $msgr
Case $exititem  
                         #NoTrayIcon
        Opt("TrayIconHide", 1)
    Filedelete (  @TempDir &"\batary.mp3" )
            exit
    Case    $aetitem
akf()
        Case    $dvbtitem 
        TogglePause()


 EndSwitch 
$battery    = _BatteryQuery()
Select
    case $battery[0] = 0
    ;Opt("TrayIconHide", 0) 
     soundplay(@TempDir &"\batary.mp3")
  case $battery[0] = 1

soundplay("")
EndSelect
sleep(3000)
WEnd
endfunc

Func _BatteryQuery()
    Local $SystemPower, $ret, $array[4]

; Setup $array and $SystemPower
    $SystemPower = DllStructCreate("ubyte;ubyte;ubyte;ubyte;ulong;ulong")
    If @error Then
        SetError(-1)
        Return $array
    EndIf

; make the DllCall
    $ret = DllCall("kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($SystemPower))
    If @error Then;DllCall Failed
        SetError(-2)
        $SystemPower = 0
        Return $array
    EndIf

    If Not $ret[0] Then; GetSystemPowerStatus Failed
        SetError(-3)
        $SystemPower = 0
        Return $array
    EndIf

; Fill the array
    $array[0] = DllStructGetData($SystemPower, 1);  AC
    $array[1] = DllStructGetData($SystemPower, 2);  Battery Charge
    $array[2] = DllStructGetData($SystemPower, 3);  Battery Charge %
    $array[3] = DllStructGetData($SystemPower, 5);  Sec Battery Left

; free the struct
    $SystemPower = 0

    Return $array
EndFunc  ;==>_BatteryQuery


Func TogglePause()
    $Paused =  NOT $Paused
    While $Paused
       
           
    $msgr = TrayGetMsg()
   
     Switch $msgr
Case $exititem  
                         #NoTrayIcon
        Opt("TrayIconHide", 1)
    Filedelete (  @TempDir &"\batary.mp3" )
            exit
    Case    $aetitem
akf()
        Case    $dvbtitem 
        TogglePause()


 EndSwitch 
       sleep(10)
    WEnd
   
EndFunc

thank you now

Edited by mesale0077

Share this post


Link to post
Share on other sites



mesale0077,

hi

tray menu work :huh2:

Global $fFlag = False

If UBound(ProcessList(@ScriptName)) > 2 Then
    Exit 0
EndIf

FileInstall("C:\batary.mp3", @TempDir & "\batary.mp3")

Opt("TrayMenuMode", 3)

$aetitem = TrayCreateItem("ACTIVE")
$dvbtitem = TrayCreateItem("DISABLE")
$exititem = TrayCreateItem("EXIT")

TraySetState()

While 1

    Switch TrayGetMsg()
            Case $exititem
                Exit
            Case $aetitem
                $fFlag = True
            Case $dvbtitem
                $fFlag = False
    EndSwitch

    If $fFlag Then

        ConsoleWrite("Active" & @CRLF) ; Just to demonstrate <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

        Switch _BatteryQuery()
            Case 0
                SoundPlay(@TempDir & "\batary.mp3")
        EndSwitch

    Else

        ConsoleWrite("Disabled" & @CRLF) ; Just to demonstrate <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    EndIf
WEnd

Func _BatteryQuery()
    Local $SystemPower, $ret, $array[4]

    ; Setup $array and $SystemPower
    $SystemPower = DllStructCreate("ubyte;ubyte;ubyte;ubyte;ulong;ulong") ; As it is Local, it is destroyed by AutoIt when the function ends <<<<<<<<<<<<<<
    If @error Then
        SetError(-1)
        Return SetError(1, 0, 0)
    EndIf

    ; make the DllCall
    $ret = DllCall("kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($SystemPower))
    If @error Then ; DllCall Failed
        Return SetError(2, 0, 0)
    EndIf

    If Not $ret[0] Then ; GetSystemPowerStatus Failed
        Return SetError(3, 0, 0)
    EndIf

    ; Fill the array
    ;$array[0] = DllStructGetData($SystemPower, 1);  AC
    ;$array[1] = DllStructGetData($SystemPower, 2);  Battery Charge
    ;$array[2] = DllStructGetData($SystemPower, 3);  Battery Charge %
    ;$array[3] = DllStructGetData($SystemPower, 5);  Sec Battery Left

    Return DllStructGetData($SystemPower, 1) ; You only used the [0] element, so why return them all? <<<<<<<<<<<<<<

EndFunc   ;==>_BatteryQuery

All clear? ;)

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

#3 ·  Posted (edited)

hi

Melba23

you are perfection

this working :huh2:

thank you

I click a tray icon, but music is playing why?

Global $fFlag = True ;no false 

If UBound(ProcessList(@ScriptName)) > 2 Then
    Exit 0
EndIf

FileInstall("C:\batary.mp3", @TempDir & "\batary.mp3")

Opt("TrayMenuMode", 3)

$aetitem = TrayCreateItem("ACTIVE")
$dvbtitem = TrayCreateItem("DISABLE")
$exititem = TrayCreateItem("EXIT")

TraySetState()

While 1

    Switch TrayGetMsg()
            Case $exititem
            Filedelete (  @TempDir &"\batary.mp3" )

                Exit
            Case $aetitem
                $fFlag = True
            Case $dvbtitem
                $fFlag = False
    EndSwitch

    If $fFlag Then

        ConsoleWrite("Active" & @CRLF) ; Just to demonstrate <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

        Switch _BatteryQuery()
            Case 1
                SoundPlay(@TempDir & "\batary.mp3")
        EndSwitch

    Else

        ConsoleWrite("Disabled" & @CRLF) ; Just to demonstrate <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    EndIf
WEnd

Func _BatteryQuery()
    Local $SystemPower, $ret, $array[4]

    ; Setup $array and $SystemPower
    $SystemPower = DllStructCreate("ubyte;ubyte;ubyte;ubyte;ulong;ulong") ; As it is Local, it is destroyed by AutoIt when the function ends <<<<<<<<<<<<<<
    If @error Then
        SetError(-1)
        Return SetError(1, 0, 0)
    EndIf

    ; make the DllCall
    $ret = DllCall("kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($SystemPower))
    If @error Then ; DllCall Failed
        Return SetError(2, 0, 0)
    EndIf

    If Not $ret[0] Then ; GetSystemPowerStatus Failed
        Return SetError(3, 0, 0)
    EndIf

    ; Fill the array
    ;$array[0] = DllStructGetData($SystemPower, 1);  AC
    ;$array[1] = DllStructGetData($SystemPower, 2);  Battery Charge
    ;$array[2] = DllStructGetData($SystemPower, 3);  Battery Charge %
    ;$array[3] = DllStructGetData($SystemPower, 5);  Sec Battery Left

    Return DllStructGetData($SystemPower, 1) ; You only used the [0] element, so why return them all? <<<<<<<<<<<<<<

EndFunc   ;==>_BatteryQuery
Edited by mesale0077

Share this post


Link to post
Share on other sites

mesale0077,

The music plays because _BatteryQuery() returns a value of 1 - which means that the value of DllStructGetData($SystemPower, 1) = 1. This is what you had in your original script. ;)

When do you want the music to play? When the battery gets low? If so then you need to return another value from the Struct and amend the Case statement. Let me know what condition you want for the music to play and I will change the condiitons accordingly. :huh2:

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

hi

thank you

When I click the tray icon is playing music,When press tray icon , I do not want to play music

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

mesale0077,

Your original script had this code: :ph34r:

Select
    case $battery[0] = 0
        ;Opt("TrayIconHide", 0) 
        soundplay(@TempDir &"\batary.mp3")
     case $battery[0] = 1
        soundplay("")
EndSelect

This means that if $battery[0] (which is set by DllStructGetData($SystemPower, 1); AC) = 1 the .mp3 file will play. The script I posted does exactly the same. ;)

I suggested above that maybe you did not want this particular condition - so I ask again: When do you want the music to sound? For example - when the battery gets to a certain level? It is easy to change - I just need you to tell me what condition should fire the sound. :alien:

M23

Edit: Apologies - i had the condition the wrong way round! :huh2:

Change the line in the earlier script to read:

Switch _BatteryQuery()
    Case 0 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        SoundPlay(@TempDir & "\batary.mp3")

Sorry! :)

Edited by Melba23

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

#7 ·  Posted (edited)

hi

thank you

code and tray menu working ;):huh2:

this code Changed

new code

-----------------------------------------------

Global $fFlag = True

If UBound(ProcessList(@ScriptName)) > 2 Then
    Exit 0
EndIf

FileInstall("C:\batary.mp3", @TempDir & "\batary.mp3")


$s          = ""
$battery    = _BatteryQuery()

opt("TrayIconDebug", 1)
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode", 3)

$aetitem = TrayCreateItem("ACTIVE")
TrayItemSetOnEvent(-1, "Close")
$dvbtitem = TrayCreateItem("DISABLE")
TrayItemSetOnEvent(-1, "Close")
$exititem = TrayCreateItem("EXIT")
TrayItemSetOnEvent(-1, "Close")

TraySetState()

While 1

    If $fFlag Then

        ConsoleWrite("Active" & @CRLF) ; Just to demonstrate <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

      $battery    = _BatteryQuery()
Select
    case $battery[0] = 0
    ;Opt("TrayIconHide", 0) 
     soundplay("C:\batary.mp3")
  case $battery[0] = 1

soundplay("")
EndSelect

    Else

        ConsoleWrite("Disabled" & @CRLF) ; Just to demonstrate <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    EndIf
    sleep(3000)
WEnd

Func _BatteryQuery()
    Local $SystemPower, $ret, $array[4]

; Setup $array and $SystemPower
    $SystemPower = DllStructCreate("ubyte;ubyte;ubyte;ubyte;ulong;ulong")
    If @error Then
        SetError(-1)
        Return $array
    EndIf

; make the DllCall
    $ret = DllCall("kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($SystemPower))
    If @error Then;DllCall Failed
        SetError(-2)
        $SystemPower = 0
        Return $array
    EndIf

    If Not $ret[0] Then; GetSystemPowerStatus Failed
        SetError(-3)
        $SystemPower = 0
        Return $array
    EndIf

; Fill the array
    $array[0] = DllStructGetData($SystemPower, 1);  AC
    $array[1] = DllStructGetData($SystemPower, 2);  Battery Charge
    $array[2] = DllStructGetData($SystemPower, 3);  Battery Charge %
    $array[3] = DllStructGetData($SystemPower, 5);  Sec Battery Left

; free the struct
    $SystemPower = 0

    Return $array
EndFunc  ;==>_BatteryQuery

Func Close() 
  
        Select
            Case @TRAY_ID = $exititem  
                         #NoTrayIcon
        Opt("TrayIconHide", 1)
    Filedelete (  @TempDir &"\batary.mp3" )
            exit
            
            Case @TRAY_ID = $aetitem
                $fFlag = True
                Case @TRAY_ID = $dvbtitem
                $fFlag = False
        EndSelect
 
EndFunc
Edited by mesale0077

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