kisstom Posted May 15, 2015 Share Posted May 15, 2015 (edited) Hi i would like to make a mp3 (or playlist, m3u) catalog program.I can make a list of files with GUICtrlCreateListViewItem. I just simple want to double click one of them and play with the default program (just like in explorer).#include <GUiConstants.au3> #include <File.au3> $Form1 = GUICreate("Form1", 322, 438, 297, 131) $MusicDir=FileSelectFolder("Please select a folder",@HomeDrive) $ListView1 = GUICtrlCreateListView("Mp3 files at " & $MusicDir, 16, 4, 289, 413) If @error Then Exit $filesArray=_FileListToArray($MusicDir,"*.mp3") For $i=1 To $filesArray[0] GUICtrlCreateListViewItem($filesArray[$i],$ListView1) Next GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Edited May 15, 2015 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 15, 2015 Moderators Share Posted May 15, 2015 kisstom,Welcome to the AutoIt forum.But please pay attention to where you post - the "Examples" section where you started this thread is clearly marked: "This is NOT a general support forum!". I have moved it for you, but would ask you to be more careful in future.And when you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags.M23 kisstom 1 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...
kisstom Posted May 15, 2015 Author Share Posted May 15, 2015 (edited) Seems i'm done , my only problem now it's not contains subdirectory. expandcollapse popup#include <File.au3> #include <GuiConstants.au3> #include <GuiListView.au3> Global $DoubleClicked = False Global $width = 450 Global $height = 438 $Form1 = GUICreate("Form1", $width, $height) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") $MusicDir=FileSelectFolder("Please select a folder",@HomeDrive) $ListView1 = GUICtrlCreateListView("Mp3 files at " & $MusicDir, 15, 5, ($width - 30), ($height - 20)) _GUICtrlListView_SetColumnWidth($ListView1, 0, ($width - 60)) ; set Column header width If @error Then Exit ;$filesArray=_FileListToArray($MusicDir,"*.mp3") ; mp3 files only $filesArray=_FileListToArray($MusicDir) ; all files For $i=1 To $filesArray[0] GUICtrlCreateListViewItem($filesArray[$i],$ListView1) Next GUISetState() While GUIGetMsg() <> -3 Sleep(10) If $DoubleClicked Then DoubleClickFunc() $DoubleClicked = False EndIf WEnd Func DoubleClickFunc() $runpath = ($MusicDir & "\" & GUICtrlRead(GUICtrlRead($ListView1))) $runpath = StringTrimRight ($runpath, 1) ;remove last character (there is a "|" character at the end i don't know why) ;ToolTip ($runpath) ; just to test ;ToolTip("Double Clicked: " & $MusicDir & "\" & GUICtrlRead(GUICtrlRead($ListView1))) ;Sleep (2000) ;ToolTip("") ShellExecute ($runpath) ; runs the double clicked file EndFunc Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam) Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return 0 $code = DllStructGetData($tagNMHDR, 3) If $wParam = $ListView1 And $code = -3 Then $DoubleClicked = True Return $GUI_RUNDEFMSG EndFunc Edited May 15, 2015 by kisstom mstfblgn 1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 15, 2015 Moderators Share Posted May 15, 2015 kisstom,my only problem now it's not contains subdirectoryUse _FileListToArrayRec to get files from within subfolders on the path.M23 kisstom 1 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...
Gianni Posted May 15, 2015 Share Posted May 15, 2015 (edited) here another way...expandcollapse popup#include <GuiListView.au3> #include <GUiConstants.au3> #include <File.au3> $Form1 = GUICreate("Form1", 322, 438, 297, 131) Global $MusicDir = FileSelectFolder("Please select a folder", @HomeDrive) $ListView1 = GUICtrlCreateListView("Mp3 files at " & $MusicDir, 16, 4, 289, 413) If @error Then Exit $filesArray = _FileListToArray($MusicDir, "*.mp3") For $i = 1 To $filesArray[0] GUICtrlCreateListViewItem($filesArray[$i], $ListView1) Next GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "_Check_Click") ; Register a user defined function for a known Windows Message ID (WM_MSG). ---------+ ; | ; WM_NOTIFY event handler for click example: http://www.autoitscript.com/forum/topic/143900-listview-onclick/#entry1013670 <---+ Func _Check_Click($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) Local $hList = GUICtrlGetHandle($ListView1) If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hList And DllStructGetData($tNMHDR, "Code") = $NM_CLICK Then ; event is from $hList and it is a $NM_CLICK ; is a Click ; manage click here EndIf ; what follows will check if it is a doubleClick and if is comming from the listview If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hList And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then ; event is from $hList and it is a $NM_DBLCLK ; is a DoubleClick $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hList) If $aLV_Click_Info[0] <> -1 Then ConsoleWrite("DoubleClick on " & _GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]) & @CRLF) Else ConsoleWrite("DoubleClick on an empty row" & @CRLF) EndIf ConsoleWrite($MusicDir & "\" & _GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]) & @CRLF) SoundPlay("") SoundPlay($MusicDir & "\" & _GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0])) EndIf Return ; $GUI_RUNDEFMSG EndFunc ;==>_Check_Click While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Edited May 15, 2015 by Chimp kisstom 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
kisstom Posted May 16, 2015 Author Share Posted May 16, 2015 Thx Melba23 and Chimp, i'll play with this Link to comment Share on other sites More sharing options...
kisstom Posted May 16, 2015 Author Share Posted May 16, 2015 kisstom,Use _FileListToArrayRec to get files from within subfolders on the path.M23 Ok, now i get all the files i need, thank you. I want to make a program that list all *.m3u (winamp playlist file) from the sected directories, double click on of them to play music.It's working now BUT i want to list only *.m3u filename not the full path. In this case i not get the full path of the file if i double click on an item.My idea is to store the full path in another variable (in the same order) and list the file names only. Is there a way to get the number of double clicked item with GUICtrlRead? Then i can get the full path from the another variable and run the file.Sorry, my English is not on the top, i hope you understand what i want. Link to comment Share on other sites More sharing options...
Gianni Posted May 17, 2015 Share Posted May 17, 2015 to get the number of double clicked item have a look to the _GUICtrlListView_SubItemHitTest functionand to get the text at that item number have a look to the _GUICtrlListView_GetItemTexthave a look in my previous post on how I used those functions kisstom 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
kisstom Posted May 17, 2015 Author Share Posted May 17, 2015 (edited) Thank you Chimp, it's working.Here is the code if someone interested:expandcollapse popup#include <GuiListView.au3> #include <GUiConstants.au3> #include <File.au3> Global $width = 500 Global $height = 438 $Form1 = GUICreate("Form1", $width, $height) Global $MusicDir = FileSelectFolder("Please select a folder", @HomeDrive) $ListView1 = GUICtrlCreateListView("Playlist files at " & $MusicDir, 15, 5, ($width - 30), ($height - 20)) _GUICtrlListView_SetColumnWidth($ListView1, 0, ($width - 60)) ; set Column header width If @error Then Exit $filesArray=_FileListToArrayRec($MusicDir, "*.m3u", 1, 1, 2, 1) ; all files, Relative to initial path (last "1"), File/folder name only (last "0") For $i = 1 To $filesArray[0] ;GUICtrlCreateListViewItem($filesArray[$i], $ListView1) GUICtrlCreateListViewItem((StringRegExpReplace($filesArray[$i], "^.*\\|\..*$", "")), $ListView1) ; display filenames only ;https://www.autoitscript.com/forum/topic/115992-extracting-just-the-filename-and-extension-from-a-full-path/ Next GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "_Check_Click") ; Register a user defined function for a known Windows Message ID (WM_MSG). ---------+ ; | ; WM_NOTIFY event handler for click example: http://www.autoitscript.com/forum/topic/143900-listview-onclick/#entry1013670 <---+ Func _Check_Click($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) Local $hList = GUICtrlGetHandle($ListView1) If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hList And DllStructGetData($tNMHDR, "Code") = $NM_CLICK Then ; event is from $hList and it is a $NM_CLICK ; is a Click ; manage click here EndIf ; what follows will check if it is a doubleClick and if is comming from the listview If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hList And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then ; event is from $hList and it is a $NM_DBLCLK ; is a DoubleClick $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hList) If $aLV_Click_Info[0] <> -1 Then ;ToolTip($aLV_Click_Info[0]) ;number of item ;ToolTip($filesArray[$aLV_Click_Info[0]+1]) ;path ;ToolTip("DoubleClick on " & _GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]) & @CRLF) ;ToolTip($MusicDir & "\" & ($filesArray[$aLV_Click_Info[0]+1])) ; test the full path ShellExecute ($MusicDir & "\" & ($filesArray[$aLV_Click_Info[0]+1])) Else ;ToolTip("DoubleClick on an empty row" & @CRLF) EndIf EndIf Return ; $GUI_RUNDEFMSG EndFunc ;==>_Check_Click While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Edited May 17, 2015 by kisstom 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