Domanda

I'm working on a Windows screensaver program, and while I'm developing it I'd like to test it by launching it from some kind of little tester program that simulates the launching done by the Windows "Screen Saver Settings" dialog. That way I can avoid having to copy my screensaver program and various support DLLs to Windows\System32 again and again.

In particular, it's the launching with the "/p" option and a window handle as a text string that I'd like to see an example of. Preferably in C#, but a test launcher program in another language is also of interest.

È stato utile?

Soluzione

The information in the answer by Vimal Raj on this thread was a major help: How to use Multiple forms in one Csharp panel in one Windows Form panel?

Here's my entire screensaver tester program, neglecting Visual Studio designer stuff:

   public partial class FormTest : Form
   {
      private readonly Form _formTinyView;

      // Constructor
      public FormTest()
      {
         InitializeComponent();

         // Create a tiny preview form and place it inside the Panel control
         _formTinyView = new Form();
         _formTinyView.FormBorderStyle = FormBorderStyle.None;
         _formTinyView.TopLevel = false;
         _formTinyView.Size = panelTinyView.Size;
         panelTinyView.Controls.Add(_formTinyView);
         _formTinyView.Visible = true;
      }


      // Display settings dialog
      private void Settings_Click(object sender, EventArgs e)
      {
         LaunchScreensaver("/c");
      }


      // Preview in tiny window
      private void TinyView_Click(object sender, EventArgs e)
      {
         LaunchScreensaver("/p " + _formTinyView.Handle);
      }


      // Standard preview
      private void Preview_Click(object sender, EventArgs e)
      {
         LaunchScreensaver("/s");
      }


      // Launch screensaver as a new process
      private static void LaunchScreensaver(string argumentString)
      {
         Process.Start(@"..\..\OutBackScreensaver\bin\Merlinia.OutBackScreensaver.exe", 
                       argumentString);
      }
   }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top