RazorTorque4X Posted February 4, 2010 Share Posted February 4, 2010 Hi everyone, I am new here and might a bit ignorant in front of you, but please remember I have just started to learn. Ok, so here is the problem : My Idea was to create a process killer that loads in taskbar and when we left click it, it shows all the process running and if we click any process it kills the process, on right click it should show a menu of about, exit, etc. I tried both (Trayonevent and tray getmsg) but I could not assign functions in loop. Here is the onevent code : Opt("TrayMenuMode",1) ;;changing option Opt("TrayOnEventMode",1) ;;here also Global $prcs = ProcessList(), $val2 ;;getting process list and declaring some more var Global $id[$prcs[0][0]] ;;id for events TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN,"primary") TraySetOnEvent($TRAY_EVENT_SECONDARYUP,"secondary") Func primary() ;;the primary function For $i = 1 To $prcs[0][0] $id[$prcs[$i][0]]=TrayCreateItem($prcs[$i][0]) ;;this works fine TrayItemSetOnEvent($id[$prcs[$i][0]], "prckill" & ($prcs[$i][0])) ;;generates error always Next EndFunc Func prckill( $param ) ;;here is the function that takes arguments If ProcessExists($param) Then ;;but all this doesn't work processclose($param) EndIf EndFunc Ok for the thing that doesn't work, I tried many other ways like Func primary() ;;the primary function For $i = 1 To $prcs[0][0] $id[$prcs[$i][0]]=TrayCreateItem($prcs[$i][0]) ;;this works fine TrayItemSetOnEvent($id[$prcs[$i][0]], "prckill" & $i ;;other version that i tried, but it still gives error Next EndFunc for $j=1 to $prcs[0][0] Func prckill & $j ;;here is where i try to initalize all the function as many process are there but it always If ProcessExists[$J][0] Then ;;says next missing endfunc missing or something else missing processclose[$j][0] ;;even this doesn't work EndIf EndFunc Next Also there are 2 or 3 more that i tired but they were wrecked too. Can anyone please guide me what to how. I think I made myself clear what I wanted to do, and how I started. If anyone wants to know how I worked in traygetmsg() mode, I can post that thing too, but basically the idea and problem is same. Please See what you can do. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2010 Moderators Share Posted February 4, 2010 RazorTorque4X, Welcome to the AutoIt forum. I am new here and might a bit ignorant in front of you, but please remember I have just started to learnWe all started there, so I would not worry too much! A couple of instant problems with what you are trying to do: 1. You can only have 1 tray menu - you use TraySetClick to determine which mouse buttons open it - you cannot have separate menus for both mouse buttons. The answer is to use the tray menu for the short right-click menu and create your own GUI to deal with the process list. 2. You cannot use parameters in OnEvent mode (well, not without a deal of faffing around with a nice UDF from martin and I have never seen it done for the tray menu) - which makes your idea of passing the parameter to prckill a non-starter. However, this problem will go away if we go the route above, because then we can read our own GUI and not have to worry about it. Here is a short script which shows what I mean - left click on the icon for the GUI, right click for the tray menu: expandcollapse popup#include <GUIConstantsEx.au3> #include <Constants.au3> #Include <GuiToolBar.au3> Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown. TrayCreateItem("About") TrayItemSetOnEvent(-1, "On_About") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "On_Exit") TraySetState() TraySetClick(8) ; Set left click to act as Play/Pause or New TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "On_List") Global $iIcon_X, $iIcon_Y ; Find the tray icon _Locate_Icon() ; Create and hide the GUI GUICreate("Process List", 200, 200, $iIcon_X - 200, $iIcon_Y - 240) GUISetState(@SW_HIDE) While 1 Switch GUIGetMsg() ; Pressing either [_] or [X] rehides the GUI Case $GUI_EVENT_CLOSE, $GUI_EVENT_MINIMIZE GUISetState(@SW_HIDE) EndSwitch WEnd Func On_List() ; Show the GUI GUISetState(@SW_SHOW) ; Obviously a lot more to go here!!! EndFunc Func _Locate_Icon () ; Find taskbar Local $aPos = WinGetPos("[Class:Shell_TrayWnd]", "") ; Start icon position calculation $iIcon_X = $aPos[0] $iIcon_Y = $aPos[1] ; Get systray handle and position Local $hSysTray_Handle = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") $aPos = ControlGetPos("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") If @error Then Return ; Continue icon position calculation $iIcon_X += $aPos[0] $iIcon_Y += $aPos[1] ; Get systray item count Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) If $iSystray_ButCount = 0 Then Return ; Look for tooltip by finding track title For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1 Local $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber) If StringInStr($sText, "ProcessKiller") = 1 Then ; Get coords of icon $aPos = _GUICtrlToolbar_GetButtonRect($hSysTray_Handle, $iSystray_ButtonNumber) ; Finalise icon position calculation $iIcon_X += $aPos[0] $iIcon_Y += $aPos[1] ExitLoop EndIf If $iSystray_ButtonNumber = $iSystray_ButCount - 1 Then Return 1 Next Return 0 EndFunc Func On_About() MsgBox(0, "About", "Whatever") EndFunc Func On_Exit() Exit EndFunc Lots of work for you to do yet. You will need to get the processes into a List/ListView within the GUI, detect a click, kill the process, etc. But that should give you a good start and you know where we are if you run into problems. Have fun. 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...
RazorTorque4X Posted February 4, 2010 Author Share Posted February 4, 2010 RazorTorque4X, Welcome to the AutoIt forum. We all started there, so I would not worry too much! A couple of instant problems with what you are trying to do: 1. You can only have 1 tray menu - you use TraySetClick to determine which mouse buttons open it - you cannot have separate menus for both mouse buttons. The answer is to use the tray menu for the short right-click menu and create your own GUI to deal with the process list. 2. You cannot use parameters in OnEvent mode (well, not without a deal of faffing around with a nice UDF from martin and I have never seen it done for the tray menu) - which makes your idea of passing the parameter to prckill a non-starter. However, this problem will go away if we go the route above, because then we can read our own GUI and not have to worry about it. Here is a short script which shows what I mean - left click on the icon for the GUI, right click for the tray menu: expandcollapse popup#include <GUIConstantsEx.au3> #include <Constants.au3> #Include <GuiToolBar.au3> Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown. TrayCreateItem("About") TrayItemSetOnEvent(-1, "On_About") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "On_Exit") TraySetState() TraySetClick(8) ; Set left click to act as Play/Pause or New TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "On_List") Global $iIcon_X, $iIcon_Y ; Find the tray icon _Locate_Icon() ; Create and hide the GUI GUICreate("Process List", 200, 200, $iIcon_X - 200, $iIcon_Y - 240) GUISetState(@SW_HIDE) While 1 Switch GUIGetMsg() ; Pressing either [_] or [X] rehides the GUI Case $GUI_EVENT_CLOSE, $GUI_EVENT_MINIMIZE GUISetState(@SW_HIDE) EndSwitch WEnd Func On_List() ; Show the GUI GUISetState(@SW_SHOW) ; Obviously a lot more to go here!!! EndFunc Func _Locate_Icon () ; Find taskbar Local $aPos = WinGetPos("[Class:Shell_TrayWnd]", "") ; Start icon position calculation $iIcon_X = $aPos[0] $iIcon_Y = $aPos[1] ; Get systray handle and position Local $hSysTray_Handle = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") $aPos = ControlGetPos("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") If @error Then Return ; Continue icon position calculation $iIcon_X += $aPos[0] $iIcon_Y += $aPos[1] ; Get systray item count Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) If $iSystray_ButCount = 0 Then Return ; Look for tooltip by finding track title For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1 Local $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber) If StringInStr($sText, "ProcessKiller") = 1 Then ; Get coords of icon $aPos = _GUICtrlToolbar_GetButtonRect($hSysTray_Handle, $iSystray_ButtonNumber) ; Finalise icon position calculation $iIcon_X += $aPos[0] $iIcon_Y += $aPos[1] ExitLoop EndIf If $iSystray_ButtonNumber = $iSystray_ButCount - 1 Then Return 1 Next Return 0 EndFunc Func On_About() MsgBox(0, "About", "Whatever") EndFunc Func On_Exit() Exit EndFunc Lots of work for you to do yet. You will need to get the processes into a List/ListView within the GUI, detect a click, kill the process, etc. But that should give you a good start and you know where we are if you run into problems. Have fun. M23 Whoa! That's a lot's of code for a newbie like me but thanks very much for taking time, there are other post here way after mine, but they have a lots of replies, why just cause I am new ? Anyway, that 's gonna take me atleast half a day to figure out and another half to make it what I want, then I'll get back again here. Really thanks for helping. Now I'll take a break to digest all this and then come back. bye Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2010 Moderators Share Posted February 4, 2010 (edited) RazorTorque4X, thanks very much for taking time [...] why just cause I am new ?No, because you had an interesting question and taken the trouble to try and write some code yourself. That is a pretty winning combination in my book. Looking forward to our next meeting. M23 P.S. When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. Edit: Typign! Edited February 4, 2010 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...
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