Pages

Monday, November 19, 2007

Day 4: launch an outside App

This is a little less formal than previous posts, but here goes. First, create a form with a button, a RichText, and a PictureBox.

Here is the source code I wrote to accomplish this. I am a big believer in examples. They tell the story in a far more eloquent way than my witty expose'.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
using System.Diagnostics;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        Process POVRay = new Process();
        

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            StringBuilder povtext = new StringBuilder();
            string camera = "camera{location <0,1,-1>*10 look_at<0,0,0>}";
            string light1 = "light_source{<0,1,0>*1000 color rgb 1}";
            string water = "plane{y,0 texture{pigment{color rgb 0.5}"+
                " finish{reflection .2 }" +
                " normal{ bumps .4 turbulence .7 }}}";
            string sphere = "sphere{<0,1,0>,1 pigment{color rgb<1,0,0>}}";

            povtext.AppendLine(camera);
            povtext.AppendLine(light1);
            povtext.AppendLine(water);
            povtext.AppendLine(sphere);

            richTextBox1.Text = povtext.ToString();

            //save to file

            using (StreamWriter sw = new StreamWriter("C:\\temp\\demo.pov"))
            {
                // Add some text to the file.                
                sw.WriteLine(povtext);
                sw.Flush();
                sw.Close();
            }


            //launch POV-RAY and create a new bitmap;
            Process POVRay = new Process();
            POVRay.StartInfo.FileName = 
                "C:\\Program Files\\POV3.6\\bin\\pvengine.exe";
            POVRay.StartInfo.Arguments = 
                "+IC:\\temp\\demo.pov +OC:\\temp\\demo.bmp +w320 +h200 -P -D /EXIT";
            POVRay.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;           

            POVRay.Start();
            POVRay.WaitForExit();
            this.pictureBox1.Load("file:C:\\temp\\demo.bmp");
           
        }
    }
}


You will need POVRay to run this.

Your assignment: figure out how to launch another application like Word, Firefox, or Notepad.

Enjoy.

No comments:

Share This!

Contact Us

Name

Email *

Message *