Results 1 to 10 of 10

Thread: [RESOLVED] Process starts but returns zero

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2012
    Posts
    87

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

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Process starts but returns zero

    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.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2012
    Posts
    87

    Re: Process starts but returns zero

    Thanks for the prompt response. So, now, how do I get the handle of Windows Photo Viewer?

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Process starts but returns zero

    Why not put a PictureBox on your Form and load the image into that?

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2012
    Posts
    87

    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.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2012
    Posts
    87

    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.

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Process starts but returns zero

    Code:
    PictureBox1.Load("c:\Path\ImageName.jpg")

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Mar 2012
    Posts
    87

    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.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Mar 2012
    Posts
    87

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width