Sign in to follow this  
Followers 0
TheCrimsonCrusader

The Almost Working Multi Selection Application Pick List

6 posts in this topic

#1 ·  Posted (edited)

This is just a simple little app that reads 'c:\applist.ini' to populate the list box with a list of applications by reading the actual line numbers. From there, when an application is selected and you click on the 'Add Application' button, it will then read the 'c:\cmdlist.ini' by reading the actual line numbers and then appending that line of text to 'c:\applist.ini'.

I did this just so the application list and the commands and could be modified external from the AutoIt script. Now I have it enabled to select multiple entries, but the problem is, it won't append the ones that are selected, only the very last one on the list. I know my logic is flawed on what I have in the 'AppPressed' button function, but I layed it out similar to what it would be assuming I was using the right commands ofter than the If and Then statements.

So where am I messing up in the 'FuncAppPressed' section? It does everything I want it to with the exception of it only adding the very last entry that is selected. I see there are commands such as '_GUICtrlListBox_GetSel' that may be in the ballpark, but I get lost pretty quick looking at the sample scripts due to their length.

CODE
#include <GUIConstants.au3>

Opt("GUIResizeMode", 1)

Opt("GUIOnEventMode", 1)

$Form = GUICreate("test", 310, 380, -1, -1)

$Tab1 = GUICtrlCreateTab(0, 0, 308, 481)

GUICtrlSetFont (-1,-1,800)

GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)

$TabSheet1 = GUICtrlCreateTabItem("App Tab")

$list = GUICtrlCreateList("", 25, 70, 272, 200, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_EXTENDEDSEL))

GUICtrlSetFont (-1,-1,800)

$app1=FileReadLine("c:\applist.ini", "1")

$app2=FileReadLine("c:\applist.ini", "2")

$app3=FileReadLine("c:\applist.ini", "3")

GUICtrlSetData(-1, $app1 & "|" & $app2 & "|" & $app3,$app1)

$AddApp = GUICtrlCreateButton ("Add Application", 25, 270, 108)

GUICtrlSetFont (-1,-1,800)

GUICtrlSetOnEvent(-1, "AppPressed")

$View = GUICtrlCreateButton ("View Application List", 160, 270, 138)

GUICtrlSetFont (-1,-1,800)

GUICtrlSetOnEvent(-1, "ViewPressed")

GUICtrlCreateLabel("Application List Builder:",25, 40, 200, 240)

GUICtrlSetFont (-1,10,800,-1)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case Else

EndSelect

Wend

Func AppPressed()

$Read = GUICtrlRead($list)

If $Read = $app1 Then

$app1_1=FileReadLine("c:\cmdlist.ini", "1")

FileWriteLine("c:\appinstall.bat", $app1_1)

EndIf

If $Read = $app2 Then

$app2_2=FileReadLine("c:\cmdlist.ini", "2")

FileWriteLine("c:\appinstall.bat", $app2_2)

EndIf

If $Read = $app3 Then

$app3_3=FileReadLine("c:\cmdlist.ini", "3")

FileWriteLine("c:\appinstall.bat", $app3_3)

EndIf

EndFunc

Func ViewPressed()

run("notepad.exe c:\appinstall.bat")

EndFunc

Func SpecialEvents()

Select

Case @GUI_CTRLID = $GUI_EVENT_CLOSE

Exit

EndSelect

EndFunc

Edited by TheCrimsonCrusader

Share this post


Link to post
Share on other sites



*bump*

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

GUICtrlRead does not support multiselect.

See _GUICtrlListBox_GetSelItemsText

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Oh well, that example is out of my league. It randomly generates the output that shows up in the control list box and if I try to work with that, it will be far more broken then the one above(after I get done with it anyway) :) that I can't complete. The best I have been able to do is select one item, click the add button, then select another item and click the add button, etc.

Edited by TheCrimsonCrusader

Share this post


Link to post
Share on other sites

Instead of text file you can use an ini file in which the key is the application name and the value is the application path, name and cmdlist. Now that you have the ini file you can create a 2 dimensional array using IniReadSection() function which contains all needed information Example:

applist.ini

[Application]

AutoIt v3 = c:\autoit-v3-setup.exe /s

App2 = \\Server\ShareFolder\App2.exe /qn

App3 = \\Server\ShareFolder\App3.exe /silent /noreboot

#include <GUIConstants.au3>
#Include <GuiListBox.au3>

Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)

Global $Apps
Global $BatchFile = 'c:\appinstall.bat'
Local $IniFile = @ScriptDir & '\applist.ini'

$Form = GUICreate("test", 310, 380, -1, -1)
$Tab1 = GUICtrlCreateTab(0, 0, 308, 481)
GUICtrlSetFont(-1, -1, 800)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("App Tab")
$list = GUICtrlCreateList("", 25, 70, 272, 200, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_EXTENDEDSEL))
GUICtrlSetFont(-1, -1, 800)

$Apps = IniReadSection($IniFile, 'Application')
If IsArray($Apps) Then 
    For $x = 1 To $Apps[0][0]
        _GUICtrlListBox_InsertString($list, $Apps[$x][0])
    Next
EndIf

$AddApp = GUICtrlCreateButton("Add Application", 25, 270, 108)
GUICtrlSetFont(-1, -1, 800)
GUICtrlSetOnEvent(-1, "AppPressed")
$View = GUICtrlCreateButton("View Application List", 160, 270, 138)
GUICtrlSetFont(-1, -1, 800)
GUICtrlSetOnEvent(-1, "ViewPressed")
GUICtrlCreateLabel("Application List Builder:", 25, 40, 200, 240)
GUICtrlSetFont(-1, 10, 800, -1)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
    EndSelect
WEnd

Func AppPressed()
    $GetSelected = _GUICtrlListBox_GetSelItems($list)
    
    If $GetSelected[0] > 0 Then
        For $x = 1 To $GetSelected[0]
            FileWriteLine($BatchFile, $Apps[$GetSelected[$x] + 1][1])
        Next
    EndIf
EndFunc   ;==>AppPressed

Func ViewPressed()
    Run("notepad.exe " & $BatchFile)
EndFunc   ;==>ViewPressed

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit
    EndSelect
EndFunc   ;==>SpecialEvents

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Oh well, that example is out of my league. It randomly generates the output that shows up in the control list box and if I try to work with that, it will be far more broken then the one above(after I get done with it anyway) :) that I can't complete. The best I have been able to do is select one item, click the add button, then select another item and click the add button, etc.

Ah, that makes sense and works much better as far as the philosophy of handling the commands within the same INI file. Thank you sir! It's very much appreciated!

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