This widget will let you browse for a folder and select a playlist. Just set the root when you call BrowseForFolder.
use Win32::GUI; use Win32::Sound; my $folder = Win32::GUI::BrowseForFolder( -root => "C:\\Program Files", -includefiles => 1, ); print "Selected: $folder\n"; opendir DIR, $folder or die "Can't read $folder: $!\n"; my @files = grep{ -f "$folder\\$_" }readdir DIR; closedir DIR; $W = new GUI::Window( -title => "Select Playlist", -left => 100, -top => 100, -width => 360, -height => 210, -style => 1024 | WS_BORDER | WS_CAPTION | WS_SYSMENU, -name => "Window", ) or die "new Window\n"; $List1 = $W->AddListbox( -name => "List1", -left => 5, -top => 5, -height => 155, -menu => 1, -tabstop => 1, -group => 1, -width => 100, -foreground => [255, 255, 255], -background => [64, 64, 64], -style => WS_VSCROLL | WS_VISIBLE | WS_CHILD, ) or die "new Listbox\n"; $List1->SendMessage(0x0195, 201, 0); $List1->AddString($_) for sort @files; $List1->Select(0); $List2 = $W->AddListbox( -name => "List2", -style => WS_VSCROLL | WS_VISIBLE | WS_CHILD, -left => 250, -top => 5, -height => 155, -menu => 2, -tabstop => 1, -group => 1, -width => 100, -vscroll => 1, ) or die "new Listbox\n"; $Add = $W->AddButton( -text => "Add >", -left => 125, -top => 5, -width => 100, -menu => 3, -name => "Add" ) or die "new Button"; $Add = $W->AddButton( -text => "Skip", -left => 125, -top => 35, -width => 100, -menu => 4, -name => "Skip" ) or die "new Button"; $AddAll = $W->AddButton( -text => "All >>", -left => 125, -top => 65, -width => 100, -menu => 5, -name => "AddAll" ) or die "new Button"; $Remove = $W->AddButton( -text => "< Remove", -left => 125, -top => 95, -width => 100, -menu => 6, -name => "Remove" ) or die "new Button"; $RemoveAll = $W->AddButton( -text => "<< All", -left => 125, -top => 125, -width => 100, -menu => 7, -name => "RemoveAll" ) or die "new Button"; $Close = $W->AddButton( -text => "Play", -left => 250, -top => 160, -width => 100, -name => "Play" ) or die "new Button"; $W->Show; $return = $W->Dialog(); sub Add_Click { my $sel = $List1->SelectedItem(); if($sel != -1) { my $num = $List2->InsertItem($List1->GetString($sel)); $List2->Select($num); $sel = -1 if $sel > $List1->Count-2; $List1->Select($sel+1); } else { Win32::Sound::Play("SystemDefault", SND_ASYNC); } return 1; } sub Skip_Click { my $sel = $List1->SelectedItem() || 0; $sel = -1 if $sel > $List1->Count-2; $List1->Select($sel+1); return 1; } sub Remove_Click { my $sel = $List2->SelectedItem(); if($sel != -1) { $List2->RemoveItem($sel); $sel-- if $List2->Count <= $sel; $List2->Select($sel) if $sel >= 0; } else { Win32::Sound::Play("SystemDefault", SND_ASYNC); } return 1; } sub AddAll_Click { for $i (0..$List1->Count-1) { $List2->InsertItem($List1->GetString($i)); } $List2->Select($List2->Count-1); return 1; } sub RemoveAll_Click { if($List2->Count > 0) { $List2->Clear; } else { Win32::Sound::Play("SystemDefault", SND_ASYNC); } return 1; } sub Play_Click { for $i (0..$List2->Count-1) { print "Play: ", $List2->GetString($i), "\n"; } return 1; }
cheers
tachyon
In reply to Re: BrowseForFolder usage
by tachyon
in thread BrowseForFolder usage
by HabitForming
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |