Following code in VB.NET opens a OpenFileDialog, user chooses a JPG file, then the program opens WinPhotoViewer for printing selected JPG. OS is 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)
Problem is. Now I want to open MULTIPLE JPG files, and to show the print dialog directly, for printing all of them, on a single page as thumbs, or in many pages. Goal is to print multiple jpgs WITH photoviewer.. how can I do this?, tried putting many filenames in the start String, like "1.jpg" "2.jpg" , but didn't work.
Now I'm trying with a cmd-line:
rundll32 "%ProgramFiles%\Windows Photo Viewer\Photoviewer.dll", ImageView_Fullscreen c:\1.jpg & c:\2.jpg
does opens multiple files (but at different instances), but now I need to apply the Print Switch command, and cmd-line switches for photoviewer.dll seems not to be documented..
Unless the program allows command line switches to do what your want (which I highly doubt)(check 'Photoviewer.dll ?' or 'Photoviewer.dll /?'), you will have to do this through something like Sendkeys which is not real reliable. But, this all gets MUCH harder when you want to do this with multiple files and the app launches multiple instances of the application.
You used Process.Start()
which is good because it will give you the handle to the application that started but it sounds like it started multiple applications with multiple handles, not good. I would suggest you do process.start for each file, use sendkeys, wait for application to close, then process.start the next file.
Today I needed to open several pictures in the Windows Photo Viewer, opening only one instance.
Usually, it's enough to open the image itself directly, and then the user uses the arrows to browse through the images.
However, when the image is in a Temp folder, the arrows are disabled. The alternative is to open the container folder, and the arrows are then enabled.
Here is my code in 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
And the same code in 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
}
However, there must be a more suitable approach than the one requested by the questioner, because using Windows Explorer, selecting two pictures from a folder that contains several pictures causes the Windows Photo Viewer to browse through these two pictures only.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.