我知道许多基于 perl 的 gui 模块很容易做到这一点,但我对Prima或Tk等以外 的方法感到好奇。
我想将此对话框(看起来像 Windows Explorer)称为命令行包。
是否有任何类似于system('');
命令的可能。
请注意,我需要通过 perl 打开和处理此类对话框选择的文件。
我知道许多基于 perl 的 gui 模块很容易做到这一点,但我对Prima或Tk等以外 的方法感到好奇。
我想将此对话框(看起来像 Windows Explorer)称为命令行包。
是否有任何类似于system('');
命令的可能。
请注意,我需要通过 perl 打开和处理此类对话框选择的文件。
这并不容易,首先您必须构建 OpenFileDialog api 所需的数据结构,与系统进行低级别交互,跟踪文件句柄,然后获取并解析结果结构。
有一些可怕的黑客可以保存 Windows 脚本,并按照您的建议使用系统从 perl 运行它。请记住,这需要正确的权限和安装的脚本语言。
# From http://www.pcreview.co.uk/threads/launching-a-search-explorer-exe-form-the-command-line.1468270/
system( q{"echo CreateObject("Shell.Application").FindFiles >%temp%\myff.vbs"} ); #setup script
my @files = system( "cscript.exe //Nologo %temp%\myff.vbs" ); # Get files
system( "del %temp%\myff.vbs" ); # Cleanup
Win32::GUI 的作者做了很大的简化工作,
my @file = Win32::GUI::GetOpenFileName ();
或者使用一些有用的选项,如过滤、起始目录和窗口标题。
# A simple open file with graphic filers
my ( @file, $file );
my ( @parms );
push @parms,
-filter =>
[ 'TIF - Tagged Image Format', '*.tif',
'BMP - Windows Bitmap', '*.bmp',
'GIF - Graphics Interchange Format', '*.gif',
'JPG - Joint Photographics Experts Group', '*.jpg',
'All Files - *', '*'
],
-directory => "c:\\program files",
-title => 'Select a file';
push @parms, -file => $lastfile if $lastfile;
@file = Win32::GUI::GetOpenFileName ( @parms );