[RESOLVED] Process starts but returns zero
Hi All,
I am trying to grab the handle of a .jpg document so that I can place it on a form. The following line of code returns zero even though the image files opens up in Windows Photo Viewer.
Code:
dim p as Process = Process.start("MyPhoto.jpg")
The line of code works without problems when starting other Windows applications. Is Windows Photo Viewer not a process? Are there situations where an application starts without creating an instance of a process?
Please, help explain what is going on. Thanks.
Re: Process starts but returns zero
Quote:
Are there situations where an application starts without creating an instance of a process?
Many. If not, indeed, many many! Windows Photo Viewer is an extension of Explorer/Windows system and therefore does not create a new process when activated. Single instance programs, if already running, will likewise not necessarily return a value from Process.Start.
Re: Process starts but returns zero
Thanks for the prompt response. So, now, how do I get the handle of Windows Photo Viewer?
Re: Process starts but returns zero
API, FindWindow or similar is probably your only hope. Kinda wondering why you need to though. What does Photo Viewer do that you can't do within your application?
Re: Process starts but returns zero
Why not put a PictureBox on your Form and load the image into that?
Re: Process starts but returns zero
I need to dynamically arrange multiple documents for viewing on a screen. JPEG files are some of the required documents.
FindWindow would be alright if I know the classname of the document the user would open at any point in time, but I don't and I cannot dictate the application the user should open.
Re: Process starts but returns zero
Putting the image in a picturebox at runtime would require me to know the handle of the image window. This is the challenge; I cannot get the handle via the process object because the process returns zero.
Re: Process starts but returns zero
Code:
PictureBox1.Load("c:\Path\ImageName.jpg")
Re: Process starts but returns zero
Placing the image in picturebox is really very nice way to do without the handle. However, my task is to have four child forms on an MDI parent. The user clicks on the form where he or she wants the document displayed. At the end of viewing or modification of the document, the user closes the application thereby making the child form available for another document. My code is already working this way except for JPG files. I guess placing the image window in a picturebox will require another means of closing the application and freeing the form. If I could just get the handle of the image window, then I will not need to write a different code snippet to deal with JPG files. Truly, thanks for the suggestion. I will experiment with it.
Re: Process starts but returns zero
Glad to say that I found the answer to my problem. The following commands were causing "Object reference not set to an instance of an object".
Code:
dim application = Process.Start("C:\Photos\MyPhoto.jpg")
application.WaitForInputIdle(1000)
application.Refresh()
I simply commented out the last two lines and the code now runs as expected.