繁体   English   中英

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

[英]How to open multiple files in Windows Photoviewer from VB.NET?

以下 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)

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

现在我正在尝试使用命令行:

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

确实会打开多个文件(但在不同的情况下),但现在我需要应用打印开关命令,并且 photoviewer.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:\Users\Picsonald\AppData\Local\Temp\SubFolder\photo1.jpg"
    Dim directoryPath As String = "C:\Users\Picsonald\AppData\Local\Temp\SubFolder"
    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:\Users\Picsonald\AppData\Local\Temp\SubFolder\photo1.jpg";
    string directoryPath = @"C:\Users\Picsonald\AppData\Local\Temp\SubFolder";
    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 照片查看器仅浏览这两张图片。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM