如何从 VB.NET 在Windows Photoviewer中打开多个文件



以下代码 VB.NET 打开一个OpenFileDialog,用户选择一个JPG文件,然后程序打开WinPhotoViewer以打印选定的JPG。操作系统是Win7

Sub CmdImprimirJPGClick(sender As Object, e As EventArgs)
Dim filePath As String = ""
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.Filter = "JPG files (*.jpg , *.jpeg)|*.jpg;*.jpeg|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 1
'openfiledialog1.Multiselect = True   
openFileDialog1.RestoreDirectory = True
If (DialogResult.OK) = openFileDialog1.ShowDialog(Me) Then
        filePath = openFileDialog1.FileName     
Else
        Exit Sub
End If
Dim oProc As New ProcessStartInfo(filePath)
oProc.verb = "Print"
oProc.CreateNoWindow = True
oProc.WindowStyle = ProcessWindowStyle.Hidden
Process.Start(oProc)

问题是。现在我想打开多个JPG文件,并直接显示打印对话框,以便在单个页面上打印所有文件,作为拇指或在多个页面上打印。目标是使用照片查看器打印多个jpg。我该怎么做?,尝试在开始字符串中放置许多文件名,例如"1.jpg"2.jpg",但没有工作。

现在我正在尝试使用 cmd 行:

rundll32 "%ProgramFiles%Windows Photo ViewerPhotoviewer.dll", ImageView_Fullscreen c:1.jpg & c:2.jpg

确实打开了多个文件(但在不同的实例),但现在我需要应用打印开关命令,而用于照片查看器的cmd线开关.dll似乎没有记录在案。

除非程序允许命令行开关做你想要的事情(我非常怀疑)(选中"Photoviewer.dll?"或"Photoviewer.dll/?"),否则你将不得不通过类似Sendkeys的东西来做到这一点,这并不真正可靠。 但是,当您想对多个文件执行此操作并且应用程序启动应用程序的多个实例时,这一切都变得更加困难。

你用了Process.Start()这很好,因为它会给你启动的应用程序的句柄,但听起来它用多个句柄启动了多个应用程序,不好。 我建议你为每个文件做process.start,使用sendkeys,等待应用程序关闭,然后process.start下一个文件。

今天我需要

在Windows照片查看器中打开几张图片,只打开一个实例。

通常,直接打开图像本身就足够了,然后用户使用箭头浏览图像。

但是,当图像位于 Temp 文件夹中时,箭头将被禁用。另一种方法是打开容器文件夹,然后启用箭头。

这是我在 VB 中的代码:

Private Sub BtnLoad_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim filePath As String = "C:UsersPicsonaldAppDataLocalTempSubFolderphoto1.jpg"
    Dim directoryPath As String = "C:UsersPicsonaldAppDataLocalTempSubFolder"
    OpenPhotoViewer(filePath) ' Open the picture, but arrow are disabled (cause of Temp folder ?) :(
    OpenPhotoViewer(directoryPath) ' Open a picture located in the directory, and arrow are enabled :) <- Several pictures can be browsed
End Sub
Private Sub OpenPhotoViewer(pathToOpen As String)
    ' Finding the PhotoViewer.dll full path...
    Dim photoViewerPath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles).Replace(" (x86)", String.Empty), "Windows Photo Viewer", "PhotoViewer.dll")
    If Not File.Exists(photoViewerPath) Then
        photoViewerPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFilesX86), "Windows Photo Viewer", "PhotoViewer.dll")
    End If
    ' Construct arguments to specify element to display
    Dim argument As String = String.Concat("""", photoViewerPath, """, ImageView_Fullscreen " + pathToOpen)
    Dim psi As ProcessStartInfo = New ProcessStartInfo("rundll32.exe", argument)
    psi.UseShellExecute = True
    Process.Start(psi) ' Run the Microsoft Photo Viewer
End Sub

C# 中的相同代码:

private void BtnLoad_Click(object sender, EventArgs e)
{
    string filePath = @"C:UsersPicsonaldAppDataLocalTempSubFolderphoto1.jpg";
    string directoryPath = @"C:UsersPicsonaldAppDataLocalTempSubFolder";
    OpenPhotoViewer(filePath); // Open the picture, but arrow are disabled (cause of Temp folder ?) :(
    OpenPhotoViewer(directoryPath); // Open a picture located in the directory, and arrow are enabled :) <- Several pictures can be browsed
}
private void OpenPhotoViewer(string pathToOpen)
{
    // Finding the PhotoViewer.dll full path...
    string photoViewerPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles).Replace(" (x86)", String.Empty), "Windows Photo Viewer", "PhotoViewer.dll");
    if (!File.Exists(photoViewerPath))
    {
        photoViewerPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFilesX86), "Windows Photo Viewer", "PhotoViewer.dll");
    }
    // Construct arguments to specify element to display
    string argument = string.Concat(""", photoViewerPath, "", ImageView_Fullscreen " + pathToOpen);
    ProcessStartInfo psi = new ProcessStartInfo("rundll32.exe", argument);
    psi.UseShellExecute = true;
    Process.Start(psi); // Run the Microsoft Photo Viewer
}

但是,必须有比提问者请求的方法更合适的方法,因为使用 Windows 资源管理器,从包含多张图片的文件夹中选择两张图片会导致 Windows 照片查看器仅浏览这两张图片。

最新更新