Jump to content
Sign in to follow this  
Adjed

Help with GUI

Recommended Posts

Adjed

Hi, I have a little problem with my GUI. I have a main window and in it i have a list, I want the list to update to view all my processes when i click a "list processes" button. I also want it to work like i click a process in the list and then it close it with ProcessClose("$process") by using a button. Here is my code that don't work:

;Main GUI
GuiCreate("Gui", 750, 376,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
;buttons
$Button_28 = GuiCtrlCreateButton("List Processes", 280, 180, 100, 20)
$Button_26 = GuiCtrlCreateButton("Kill Process", 280, 160, 100, 20)
;list
$List_34 = GuiCtrlCreateList("Processes", 280, 210, 100, 123)

GuiSetState()
;main loop
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_28
        $list = ProcessList()
            for $i = 1 to $list[0][0]
        next
        GUICtrlSetData($list_34, $list)
         Case $msg = $button_26
                ProcessClose("$process")
                ;I have no idea how to do this either.
    EndSelect
WEnd
Exit

I took the List processes code from the manual but it doesn't work.

This might be in the GUI help forum but i didn't see it sad.gif

Share this post


Link to post
Share on other sites
jezzzzy

Ok. You have a few problems here working together.

First, your list wasn't working because you weren't using guictrlsetdata() to actually set anything. A good strategy for testing things like this is to change "GUICtrlSetData($list_34, $list)" to a msg box showing your $list like this: "MsgBox(0,"test",$list)". That will show you that your $list value didn't contain any data because the ProcessList() function returns an array. Take a look at how I created a variable from the values in the array and then assigned it to the list.

Second, your process kill function. ProcessClose() only needs the name of the process passed. The _GUICtrlListGetSelItemsText() function accomplishes this. I added a For/Next loop to allow for multiple selections. Also, you can see here where I used the MsgBox method to make sure my ProcessClose() command was doing what I thought it should be doing. Throw in the error check to make sure something is actually selected and you're all set. Please look through this code and compare to what you had. It should make sense.

;Main GUI
#include <GUIConstants.au3>
#Include <GuiList.au3>

GuiCreate("Gui", 750, 376,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
;variables
Dim $listvalue, $listselect
;buttons
$Button_28 = GuiCtrlCreateButton("List Processes", 280, 180, 100, 20)
$Button_26 = GuiCtrlCreateButton("Kill Process", 280, 160, 100, 20)
;list
$List_34 = GuiCtrlCreateList("--Process List--", 280, 210, 100, 123, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_MULTIPLESEL))

GuiSetState()
;main loop
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_28
            $listvalue = ""
            GUICtrlSetData($list_34, "")
            $list = ProcessList()
            for $i = 1 to $list[0][0]
                $listvalue = $listvalue & $list[$i][0] & "|"
            next
            GUICtrlSetData($list_34, $listvalue)
        Case $msg = $button_26
            $listselect = _GUICtrlListGetSelItemsText($List_34)
            If (Not IsArray($listselect)) Then
                MsgBox(16, "Error", "Nothing selected")
            Else
                For $i = 1 To $listselect[0]
                    ;MsgBox(0,"test",$listselect[$i])
                    ProcessClose($listselect[$i])
                Next
            EndIf
    EndSelect
WEnd
Exit
Edited by jezzzzy

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  

×