Jump to content

Help Me About Listview


PC.MAX
 Share

Recommended Posts

#region --- GuiBuilder code Start ---
; Script generated by AutoBuilder 0.6 Prototype

#include <GuiConstants.au3>

GuiCreate("MP3 Player", 800, 363,-1, -1)

$list = GUICtrlCreateListView("Song name|Song destination", 30, 20,590, 266)
$openplay = GuiCtrlCreateButton("Open a playlist", 650, 20, 140, 40)
$add = GUICtrlCreateButton("Add a song to the playlist",650,120,140,40)
$save = GuiCtrlCreateButton("Save playlist", 650, 70, 140, 40)
$open = GuiCtrlCreateButton("Open the selected song", 30, 300, 290, 30)
$remove = GuiCtrlCreateButton("Remove the selected song from the playlist", 340, 300, 280, 30)
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $add
        $dia = FileOpenDialog("Add a song","::{450D8FBA-AD25-11D0-98A8-0800361B1103}","MP3's and WAVs (*.mp3;*.wav)")
        If @error  Then 
            Else
        $FullPath = StringSplit($dia,"\")
        $PathFile = $FullPath[UBound($FullPath)-1]
        GuiCtrlCreateListViewItem($PathFile & "|" & $dia,$list)
        EndIf
    Case $msg = $open
        if GUICtrlRead(GUICtrlRead($list)) = "" then ContinueLoop
        $FullPath = StringSplit(GUICtrlRead(GUICtrlRead($list)),"|")
        $FullPath = $FullPath[UBound($FullPath)-1]
        $string = @COMSPEC & " /c start " & FileGetShortName($FullPath)
        Run($string)
    Case $msg = $remove
        if GUICtrlRead(GUICtrlRead($list)) = "" then ContinueLoop
        GUICtrlDelete(GUICtrlRead($list))
    Case $msg = $openplay
        $dia = FileOpenDialog("Open a playlist",@ScriptDir,"Playlist file (*.pli)")
        if @error Then
        Else
        $file = FileOpen($dia,0)
        $line = ""
        While 1
            $line = FileReadLine($file)
        GUICtrlCreateListViewItem($list,$line)
        If @error = -1 Then ExitLoop
        Wend
            FileClose($file)
        EndIf
    Case $msg = $save
        $dia = FileSaveDialog("Save playlist",@ScriptDir,"Playlist file (*.pli)")
        if @error then ContinueLoop
            if StringRight($dia,4) = ".pli" Then
                Else
                $dia = $dia & ".pli"
            EndIf
    EndSelect
WEnd
Exit
#endregion --- GuiBuilder generated code End ---

After the last case ($msg = $save) The program will see whether the path ends with .pli or not

if it doesnt the program will add .pli to the path.

after that I want it to save the items from the listview and save all of the items to that .pli file.

I couldnt find a way to do that.

Link to comment
Share on other sites

Hi,

I think it's not a very good beginning in your script because when you create your listview, no array-variable is used to call back the listviewitem.

Well, it looks to be easy enough about the theory :

- insert all the items in an array using a loop (for...next, for example)

#Include <GuiListView.au3>
...
dim $array[$end+1]
$i = 1
for $i = 1 to $end
$array[$i]=_GUICtrlListViewInsertItem($h_listview, $i_index, $s_text)

Like it, you can use for...next to save your items by saving the array :

_FileWriteFromArray($FilePath, $array, 1)

_FileWriteFromArray has a parameter set to 1 because 0=index (in this case= number of files of the playlist)

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...