C#でムービースクリーンセーバー

ムービースクリーンセーバーを作ったってはなしだけど、作るのに必要な情報は入って無いんで自分で調べて書いてみた。

参考は以下の二つ


以下ソース。いらないものは極力削ってます。

using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX.AudioVideoPlayback;

public class SimpleScreenSaver : Form {
  private Video player;
  
  public SimpleScreenSaver() {
    this.FormBorderStyle = FormBorderStyle.None;
    this.WindowState = FormWindowState.Maximized;
    this.KeyDown += new KeyEventHandler(this.MyKeyDown);
    this.MouseDown += new MouseEventHandler(this.MyMouseDown);
    this.Load += new EventHandler(this.MyLoad);
    this.ClientSize = new Size(640, 480);
    this.player = new Video("movie.avi");
    this.player.Owner = this;
  }
  
  private void MyLoad(object sender, EventArgs ev) {
    this.player.Play();
  }
  
  private void MyMouseDown(object sender, MouseEventArgs ev) {
    Application.Exit();
  }
  
  private void MyKeyDown(object sender, KeyEventArgs ev) {
    Application.Exit();
  }
  
  [STAThread] static void Main(string[] args) {
    if (args.Length == 0 || string.Compare(args[0], "/s", true) == 0) {
      Form screenSaver = new SimpleScreenSaver();
      screenSaver.ShowDialog();
    }
    Application.Exit();
  }
}


cscでのビルドには/r:Microsoft.DirectX.AudioVideoPlayback.dllが必要だけど、これはc:\WINDOWS\Microsoft.NET\DirectX for Managed Code\*\以下にあるのでそれを使う。できたexeファイルの拡張子を.scrにしてmovie.aviとともにc:\WINDOWS\system32\におく。(ムービーの位置は別の場所にして絶対パスのほうがいいかも)。


一瞬窓が出るのがアレですが、スクリーンセーバとして全画面動画再生されましたw
このコードからいろいろループとかつけていくことになるのかな。