Jump to content

GUICtrlRead from loop/array


Recommended Posts

Hi,

I've started coding with AutoIt some days ago and have some problems - I hope you can help me woth these...

Here is what I want to do:

I read a list of programs from a XML file (BTW: Thanks to the Author of XMLDomWrapper - It's great) and let AutoIt create a array of all currently running programs in a tray menu. Thats works good but I want to give the current .exe/processname of the running program back to a handler ("Func stop_process") to terminate it (I've change this in the code above into a ConsoleWrite for better understanding)

I've the problem that AutoIt overwrite the variable in my "for" loop and get only back one (the last) entry. Thats normal in other languages too but I want to ask if there is any option to got the calling GUI element instead of the variable name of it. In my case I call

GUICtrlRead($programm_stopping, 1)

In some languages there is a option like GUICtrlRead($this, 1) without explicit name the calling variable.

I hope you can understand my problem and can help me with this or provide a proper solution :-)

Thank you very much

Here's my code:

#include <_ModernMenuRaw.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <array.au3>
#include <_XMLDomWrapper.au3>
#include <_SysTray.au3>
#include <Process.au3>
#NoTrayIcon

;Get the first real value returned from the _XMLGetValue() return array.
Func _GetFirstValue($node)
    $ret_val = _XMLGetValue($node)
    If IsArray($ret_val) Then
        Return ($ret_val[1])
    Else
        Return SetError(1,3,0)
    EndIf
EndFunc


Global $sXMLFile = @ScriptDir & "\programs.xml"
_XMLFileOpen($sXMLFile)

Opt("GUIOnEventMode",1)

$nTrayIcon1     = _TrayIconCreate("Program Starter", "shell32.dll", -13)
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "TrayMenuRightClick")
$nTrayMenu1 = _TrayCreateContextMenu() 
$nSideItem3 = _CreateSideMenu($nTrayMenu1)
_SetSideMenuText($nSideItem3, "Program Starter")
_SetSideMenuColor($nSideItem3, 0x00FFFF) 
_SetSideMenuBkColor($nSideItem3, 0x802222)
_SetSideMenuBkGradColor($nSideItem3, 0x4477AA) 


;XML Currently running programs
$AppsRunning        =  _TrayCreateMenu("Currently running programs")
_TrayItemSetIcon(-1, "", 0)
_TrayItemSetSelIcon(-1, "shell32.dll", -14)


$getStopped = _XMLSelectNodes("/programs/systemstart/app")

For $i = 1 to $getStopped[0]
    $xmlname        = _GetFirstValue("/programs/systemstart/app[" & $i & "]/name")
    $xmlexe         = _GetFirstValue("/programs/systemstart/app[" & $i & "]/exe")
    $xmlprocessname = _GetFirstValue("/programs/systemstart/app[" & $i & "]/processname")
    


    If ProcessExists($xmlprocessname) then
        $programm_stopping = GUICtrlCreateMenuItem($xmlname, $AppsRunning)
        GUICtrlSetOnEvent(-1, "stop_process")       
    EndIf
Next

;Exit

_TrayCreateItem("")
_TrayItemSetIcon(-1, "", 0)
_TrayIconSetState()


While 1
WEnd

Func stop_process()
        ConsoleWrite(GUICtrlRead($programm_stopping, 1) & " was stopped " & @LF)
EndFunc
Edited by LORDofDOOM
Link to comment
Share on other sites

First, if you want to use Tray events (vice GUI events), then you need to set "TrayOnEventMode" vice "GuiOnEventMode" and use TraySetOnEvent() vice GuiSetOnEvent() with $TRAY_EVENT_SECONDARYDOWN.

The code displayed doesn't include a GUI.

When an event handling function is called there are macros to represent the calling event, like @TRAY_ID, @GUI_WinHandle, or @GUI_CtrlHandle.

:huh2:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

:huh2:

That has nothing to say ;-) -> In final code there should be a process watcher into this while loop :-)

I have one other question releated to GUIs: Is there a option to rebuild or recreate the complete GUI content on $GUI_EVENT_SECONDARYDOWN or in the stop_process function - I need something like this because I need to reload the running processes after I stop or start a program from my tray menu...

Thank you

Link to comment
Share on other sites

Sorry for double post, but I can't edit my thread above...

I've found a way to refresh the GUI - I've set the create into a function ("BuildMenu()") and create other function ("DeleteMenu()")to delete all fields. I call DeleteMenu() BuildMenu() into my stop_process() function... This works and my GUI will rebuild after process_stop - But I don't know if this is a proper (or a good) way to do this...

Link to comment
Share on other sites

I've read your topic already before, but the while loop has a very high CPU usage in my case. I've done this now with a modification in _ModernMenuRaw.au3 that calls my "rebuild" function before the tray menu is show - That works fine and only use CPU on usage (rightclick) :-)

Thank you :-)

Link to comment
Share on other sites

That has nothing to say ;-) -> In final code there should be a process watcher into this while loop :-)

Don't forget a Sleep() so you don't suck up your whole cpu :huh2:
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...