Friday, September 10, 2010

Window Media Player Remote Control


Window Media Player Remote Control

MADE BY:-SOURABH AGGARWAL


The user interface looks like this where you can use buttons to play, pause and eject Windows Media Player.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace WMP_RemoteControl
{
/// <summary>
/// Summary description for MainForm.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private System.Int32 iHandle;
private System.Windows.Forms.Button btnStop;
        private System.Windows.Forms.Button btnPlayPause;
        private Button btnexit;
        private Label lbltime;
        private Timer timer1;
        private IContainer components;

public MainForm()
{
//
// 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 )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#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.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
            this.btnStop = new System.Windows.Forms.Button();
            this.btnPlayPause = new System.Windows.Forms.Button();
            this.btnexit = new System.Windows.Forms.Button();
            this.lbltime = new System.Windows.Forms.Label();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.SuspendLayout();
            //
            // btnStop
            //
            this.btnStop.Location = new System.Drawing.Point(12, 87);
            this.btnStop.Name = "btnStop";
            this.btnStop.Size = new System.Drawing.Size(75, 23);
            this.btnStop.TabIndex = 0;
            this.btnStop.Text = "STOP";
            this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
            //
            // btnPlayPause
            //
            this.btnPlayPause.Location = new System.Drawing.Point(12, 45);
            this.btnPlayPause.Name = "btnPlayPause";
            this.btnPlayPause.Size = new System.Drawing.Size(75, 23);
            this.btnPlayPause.TabIndex = 1;
            this.btnPlayPause.Text = "Play/Pause";
            this.btnPlayPause.Click += new System.EventHandler(this.btnPlayPause_Click);
            //
            // btnexit
            //
            this.btnexit.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.btnexit.Image = ((System.Drawing.Image)(resources.GetObject("btnexit.Image")));
            this.btnexit.Location = new System.Drawing.Point(0, 21);
            this.btnexit.Name = "btnexit";
            this.btnexit.Size = new System.Drawing.Size(21, 18);
            this.btnexit.TabIndex = 3;
            this.btnexit.UseVisualStyleBackColor = true;
            this.btnexit.Click += new System.EventHandler(this.btnexit_Click);
            //
            // lbltime
            //
            this.lbltime.BackColor = System.Drawing.SystemColors.Info;
            this.lbltime.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.lbltime.Dock = System.Windows.Forms.DockStyle.Top;
            this.lbltime.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.lbltime.ForeColor = System.Drawing.Color.Red;
            this.lbltime.Location = new System.Drawing.Point(0, 0);
            this.lbltime.Name = "lbltime";
            this.lbltime.Size = new System.Drawing.Size(119, 18);
            this.lbltime.TabIndex = 4;
            //
            // timer1
            //
            this.timer1.Enabled = true;
            this.timer1.Interval = 1000;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            //
            // MainForm
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.ClientSize = new System.Drawing.Size(119, 194);
            this.ControlBox = false;
            this.Controls.Add(this.lbltime);
            this.Controls.Add(this.btnexit);
            this.Controls.Add(this.btnPlayPause);
            this.Controls.Add(this.btnStop);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "MainForm";
            this.Opacity = 0.7;
            this.ShowInTaskbar = false;
            this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Player Remote";
            this.TransparencyKey = System.Drawing.Color.White;
            this.Load += new System.EventHandler(this.MainForm_Load);
            this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}

private void btnStop_Click(object sender, System.EventArgs e)
{

            Win32.SendMessage(iHandle, Win32.WM_COMMAND, 0x00004979, 0x00000000);
}

private void btnPlayPause_Click(object sender, System.EventArgs e)
{
Win32.SendMessage(iHandle, Win32.WM_COMMAND, 0x00004978, 0x00000000);
}

private void MainForm_Load(object sender, System.EventArgs e)
{
            //lbltime.Text = DateTime.Now.ToLongTimeString();
// get Window handle
iHandle = Win32.FindWindow("WMPlayerApp", "Windows Media Player");
}

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btnexit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            lbltime.Text = DateTime.Now.ToLongTimeString();
        }
}
}


No comments:

Post a Comment