Search code examples
vb.netwinformsprintingphotoviewer

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


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..


Solution

  • 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.