1

以下 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 的命令行开关似乎没有记录..

4

2 回答 2

0

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

您使用Process.Start()which 很好,因为它会为您提供启动的应用程序的句柄,但听起来它启动了具有多个句柄的多个应用程序,不好。我建议您对每个文件执行 process.start,使用 sendkeys,等待应用程序关闭,然后 process.start 下一个文件。

于 2013-10-01T17:22:13.857 回答
0

今天我需要在 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 照片查看器仅浏览这两张图片。

于 2022-01-26T12:53:13.793 回答