mesale0077 Posted June 19, 2011 Share Posted June 19, 2011 (edited) hi tray menu dont work ---------------------------------------------------- ACTIVE } DISABLE } tray menu dont work EXİT } ----------------------------------------------------- expandcollapse popupGlobal $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 June 19, 2011 by mesale0077 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 19, 2011 Moderators Share Posted June 19, 2011 mesale0077, hi tray menu work expandcollapse popupGlobal $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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mesale0077 Posted June 19, 2011 Author Share Posted June 19, 2011 (edited) hi Melba23 you are perfection this working thank you I click a tray icon, but music is playing why? expandcollapse popupGlobal $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 June 19, 2011 by mesale0077 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 19, 2011 Moderators Share Posted June 19, 2011 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. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mesale0077 Posted June 19, 2011 Author Share Posted June 19, 2011 hi thank you When I click the tray icon is playing music,When press tray icon , I do not want to play music Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 19, 2011 Moderators Share Posted June 19, 2011 (edited) mesale0077,Your original script had this code: Select case $battery[0] = 0 ;Opt("TrayIconHide", 0) soundplay(@TempDir &"\batary.mp3") case $battery[0] = 1 soundplay("") EndSelectThis 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. M23Edit: Apologies - i had the condition the wrong way round! Change the line in the earlier script to read:Switch _BatteryQuery() Case 0 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< SoundPlay(@TempDir & "\batary.mp3")Sorry! Edited June 19, 2011 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mesale0077 Posted June 19, 2011 Author Share Posted June 19, 2011 (edited) hi thank you code and tray menu working this code Changed new code ----------------------------------------------- expandcollapse popupGlobal $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 June 19, 2011 by mesale0077 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now