/* Professional Windows GUI Programming Using C# by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, Zach Greenvoss, Shripad Kulkarni, Neil Whitlow Publisher: Peer Information ISBN: 1861007663 */ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using MediaPlayer ; namespace SMK_MediaPlayer { /// <summary> /// Summary description for SMKMediaPlayer. /// </summary> public class SMKMediaPlayer : System.Windows.Forms.Form { /// <summary> /// Required designer variable. /// </summary> private AxMediaPlayer.AxMediaPlayer mPlayer = null ; private System.Windows.Forms.Panel panel2; private System.Windows.Forms.NotifyIcon notifyIcon1; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.MenuItem menuItem3; private System.Windows.Forms.ImageList imageList1; private System.Windows.Forms.MenuItem menuItem4; private System.Windows.Forms.ContextMenu contextMenu1; private System.Windows.Forms.MenuItem menuItem5; private System.Windows.Forms.MenuItem menuItem6; private System.ComponentModel.IContainer components; public SMKMediaPlayer() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { notifyIcon1.Dispose() ; mPlayer.Stop() ; mPlayer.Dispose(); if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } private void streamEnded(object sender , AxMediaPlayer._MediaPlayerEvents_EndOfStreamEvent e) { this.Show(); notifyIcon1.Visible = false ; mPlayer.Stop(); mPlayer.CurrentPosition= 0.0; } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(SMKMediaPlayer)); this.panel2 = new System.Windows.Forms.Panel(); this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); this.menuItem3 = new System.Windows.Forms.MenuItem(); this.menuItem4 = new System.Windows.Forms.MenuItem(); this.imageList1 = new System.Windows.Forms.ImageList(this.components); this.contextMenu1 = new System.Windows.Forms.ContextMenu(); this.menuItem5 = new System.Windows.Forms.MenuItem(); this.menuItem6 = new System.Windows.Forms.MenuItem(); this.SuspendLayout(); // // panel2 // this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(344, 109); this.panel2.TabIndex = 1; // // notifyIcon1 // this.notifyIcon1.Text = "notifyIcon1"; this.notifyIcon1.Visible = true; // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1, this.menuItem4}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem2, this.menuItem3}); this.menuItem1.Text = "File"; // // menuItem2 // this.menuItem2.Index = 0; this.menuItem2.Text = "Open"; this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click); // // menuItem3 // this.menuItem3.Index = 1; this.menuItem3.Text = "Exit"; this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click); // // menuItem4 // this.menuItem4.Index = 1; this.menuItem4.Text = "Hide"; this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click); // // imageList1 // this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit; this.imageList1.ImageSize = new System.Drawing.Size(16, 16); this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream"))); this.imageList1.TransparentColor = System.Drawing.Color.Transparent; // // contextMenu1 // this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem5, this.menuItem6}); // // menuItem5 // this.menuItem5.Index = 0; this.menuItem5.Text = "Show"; this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click); // // menuItem6 // this.menuItem6.Index = 1; this.menuItem6.Text = "Exit"; this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click); // // SMKMediaPlayer // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(344, 109); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.panel2}); this.MaximizeBox = false; this.Menu = this.mainMenu1; this.Name = "SMKMediaPlayer"; this.Text = "ActiveX Media Player"; this.Load += new System.EventHandler(this.SMKMediaPlayer_Load); this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new SMKMediaPlayer()); } private void SMKMediaPlayer_Load(object sender, System.EventArgs e) { notifyIcon1.Icon = new Icon("EYE.ico"); notifyIcon1.Text = "SMK Media Player 1.0"; notifyIcon1.Visible = false ; notifyIcon1.DoubleClick += new EventHandler(NotifyIconDoubleClick); notifyIcon1.ContextMenu = contextMenu1 ; mPlayer = new AxMediaPlayer.AxMediaPlayer(); mPlayer.BeginInit(); mPlayer.Size = new System.Drawing.Size(292, 273); mPlayer.Location = new System.Drawing.Point(0 , 16); mPlayer.TabIndex = 0; mPlayer.Dock = System.Windows.Forms.DockStyle.Fill; this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] {this.mPlayer}); mPlayer.EndOfStream += new AxMediaPlayer._MediaPlayerEvents_EndOfStreamEventHandler(this.streamEnded); mPlayer.EndInit(); } private void menuItem2_Click(object sender, System.EventArgs e) { try { Image im = imageList1.Images[0]; OpenFileDialog fd = new OpenFileDialog(); fd.ShowDialog(); mPlayer.Open(fd.FileName); mPlayer.Play(); } catch(Exception eee) { Console.WriteLine(eee.Message); } } private void menuItem4_Click(object sender, System.EventArgs e) { notifyIcon1.Visible = true ; this.Hide(); } private void menuItem3_Click(object sender, System.EventArgs e) { Application.Exit() ; } private void menuItem5_Click(object sender, System.EventArgs e) { notifyIcon1.Visible = false; this.Show(); } private void menuItem6_Click(object sender, System.EventArgs e) { notifyIcon1.Visible = false ; Application.Exit() ; } private void NotifyIconDoubleClick(object sender, System.EventArgs e) { this.Visible = true ; this.Activate() ; this.Show() ; this.BringToFront() ; } } } SMK_MediaPlayer.zip( 181 k)