How to open pictureBox.Image in Windows Picture and fax Viewer?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aeris
    New Member
    • Dec 2009
    • 18

    #1

    How to open pictureBox.Image in Windows Picture and fax Viewer?

    Hello, sorry for disturbing.
    I have a pictureBox on my form. May i know how to open the image from the pictureBox in Windows Picture and Fax Viewer?


    I've tried the code below, but it failed because the pictureBox1.Ima ge is not in String format.

    Code:
    private void button1_Click(object sender, EventArgs e)
            {            
                Process p = new Process();
    
                p.StartInfo.FileName = "rundll32.exe";
    
                //Arguments 
    
                p.StartInfo.Arguments = @"C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen " + pictureBox1.Image;
    
                
                p.Start();    
            }
    Is anyone can help?
    Thanks in advance.

    By, Aeris.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    I think you've answered your own question. Fax and Picture Viewer opens files from a path. I don't know if it can be passed an Image object as an argument.

    So if it requires a path, then you need to provide a path. Either the one used to get an Image *into* your PictureBox... or save the picture to a temp file on hard drive, then pass that path.

    Comment

    • aeris
      New Member
      • Dec 2009
      • 18

      #3
      Thanks for replying. Let's say i had saved the image to a temp file, i want delete it automatically once the user click the close button on the Windows Picture and Fax Viewer.

      May I know how to code to detect when a Close button is clicked?
      something like
      if (WindowsPicture FaxViewer.Close == selected)
      {
      //delete the picture
      }
      what is the proper coding to detect the close button?

      Thanks in advance.
      by, Aeris.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        You won't receive events from another program. You'll have to keep a thread going that is checking {in a loop] to see if the Fax & Picture Viewer process is still active. Once the process ends, then delete the temp file.

        I notice that Windows Photo Viewer titles it's window with the photo file name. You could also keep checking to see if there is a window open with the file name. Once it no longer appears, then you can delete the temp file.

        Comment

        • aeris
          New Member
          • Dec 2009
          • 18

          #5
          Thanks so much for replying.. May I know what is the code to check if the Windows Picture and Fax viewer process is not active?

          Thanks in advance.
          By Aeris.

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            Amazing what one can find when actually reading the MSDN.
            It looks like I was wrong about not getting an event when the process ends.
            http://msdn.microsoft.com/en-us/libr...v=VS.100).aspx

            SO using this technique you can get an event when the user quits Fax and Picture Viewer

            Comment

            • GaryTexmo
              Recognized Expert Top Contributor
              • Jul 2009
              • 1501

              #7
              Something else, I don't know how helpful it is... but here you go anyway!

              If you'd prefer to use whatever viewer is associated to that file by default, I believe you can just attempt to run the image path. If there's a file association, the operating system should just launch it.

              Comment

              • tlhintoq
                Recognized Expert Specialist
                • Mar 2008
                • 3532

                #8
                If the OP does that, how will he detect *which* application has opened the image, and how will he detect when that application has closed, so he can delete the temp file?

                Comment

                • GaryTexmo
                  Recognized Expert Top Contributor
                  • Jul 2009
                  • 1501

                  #9
                  I get knowing when the process that opened the image closes, but do they need to know what opened it? In reading the above I'm not sure if it matters, but I could easily be missing it.

                  It depends on if the process they generates with the image as the command line still generates the closed event. If so then they're fine but if not then yea, they're stuck using a specific program to open it.

                  I'm not sure how the process class treats that actually. Good point T, and I'm just curious enough to find out, but it'll have to wait until after lunch :D

                  Comment

                  • GaryTexmo
                    Recognized Expert Top Contributor
                    • Jul 2009
                    • 1501

                    #10
                    You should be able to get everything you need to know launching it that way... I just confirmed that the event for the process existing does fire. You can also get the name of the process it launches with the ProcessName property.

                    Code:
                        public partial class Form1 : Form
                        {
                            public Form1()
                            {
                                InitializeComponent();
                    
                                Process p = new Process();
                                p.StartInfo.FileName = @"C:\temp\click.wav";
                                p.EnableRaisingEvents = true;
                                p.Exited += new EventHandler(p_Exited);
                    
                                p.Start();
                                Console.WriteLine(p.ProcessName);
                            }
                    
                            void p_Exited(object sender, EventArgs e)
                            {
                                MessageBox.Show("Process Done!");
                            }
                        }
                    NOTE: I'm not saying it has to be done this way, just offering alternatives :)

                    Comment

                    • aeris
                      New Member
                      • Dec 2009
                      • 18

                      #11
                      Thanks you all!
                      Thanks for the coding.
                      I think I know what should do from all your opinions. Thanks so much.
                      By, Aeris. :)

                      Comment

                      Working...