私はWindowsXPSP 3、StrawberryPerlに取り組んでいます。Perlプログラムのユーザーにファイルを選択させたいのですが。しかし、Win32 :: GUI :: GetOpenFileName()を使用する場合、デフォルトの「リスト」ファイルリストオプションではなく、「詳細」ファイルリストオプションでWindowsファイル選択ダイアログを開きたいと思います。
ネット上でグーグルすると、Windowsの「フック」機能を使用して、ファイル選択コントロールに特定のメッセージを送信する必要があるようです。それに関するドキュメントはMSDNであり、Perlでそれを適用する方法をマスターしていないようです。
Perlで正しい呼び出し構文を推奨できる人はいますか?
これが私のコードサンプルです。ファイル選択ダイアログが(デフォルトの)「リスト」オプションで開きます。
use strict;
use warnings;
use 5.014;
use Win32::Console;
use Win32::GUI();
use autodie;
use warnings qw< FATAL utf8 >;
use Carp::Always;
use Win32API::File::Time qw{:win};
use Image::ExifTool qw(:Public);
use Date::Parse;
# ...
my ( $FileName, $ImageDir, $DIR, $TopDir);
# ...
$TopDir = 'D:\My Documents';
$ImageDir = Win32::GUI::BrowseForFolder( -root => $TopDir, -includefiles => 1,);
unless ($ImageDir) {
say '$DirName not defined after calling Win32::GUI::BrowseForFolder, ',
'Photo date set line'.__LINE__;
exit;
}
else {
say "Identified directory: $ImageDir";
}
# now select a file
$FileName = Win32::GUI::GetOpenFileName( -title => 'Select an image file', -directory => $ImageDir,
-file => "\0" . " " x 256,
-filter => ["Image files (*.jpg)" => "*.jpg;*.jpeg", "All files", "*.*", ],);
unless ($FileName) {
say '$FileName not defined after calling Win32::GUI::GetOpenFileName, ',
'Photo date set line'.__LINE__;
}
else {
say "Identified image file: $FileName";
}
# ...
注:(やや)同様の投稿:http://www.perlmonks.org/?node_id = 989418