WindowsAPICodePack Taskbar videos

Codesnippets for the 4 videos on the taskbar.


Developing for Windows 7: Taskbar #1: Overlay Icon:

using Microsoft.WindowsAPICodePack.Taskbar;
        TaskbarManager taskbar = TaskbarManager.Instance;
        Icon play, pause, stop;
        public MainWindow()
        {
            //...
            play = new Icon((Stream)Application.GetResourceStream(new Uri("pack://application:,,,/VideoPlayer;component/Play.ico")).Stream);
            stop = new Icon((Stream)Application.GetResourceStream(new Uri("pack://application:,,,/VideoPlayer;component/Stop.ico")).Stream);
            pause = new Icon((Stream)Application.GetResourceStream(new Uri("pack://application:,,,/VideoPlayer;component/Pause.ico")).Stream);
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //Play button
            taskbar.SetOverlayIcon(play, "Playing");
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            //Pause button
            taskbar.SetOverlayIcon(pause, "Paused");
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            //Stop button
            taskbar.SetOverlayIcon(stop, "Stopped");
        }

Developing for Windows 7: Taskbar #2: Progress Bar:

        private void slider_seek_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            taskbar.SetProgressValue((int)slider_seek.Value, (int)slider_seek.Maximum);
        }
            taskbar.SetProgressState(TaskbarProgressBarState.Paused); //Yellow
            taskbar.SetProgressState(TaskbarProgressBarState.Error); //Red
            taskbar.SetProgressState(TaskbarProgressBarState.Normal); //Green

Developing for Windows 7: Taskbar #3: Controlling the (Windows Aero) Thumbnail

        using System.Windows.Interop;
        private void Window_LayoutUpdated(object sender, EventArgs e)
        {
            Vector v = VisualTreeHelper.GetOffset(mediaElement1);
            TaskbarManager.Instance.TabbedThumbnail.SetThumbnailClip((new WindowInteropHelper(this)).Handle, new Rectangle((int)v.X, (int)v.Y, (int)mediaElement1.RenderSize.Width, (int)mediaElement1.RenderSize.Height));
            //For windows forms:
            //TaskbarManager.Instance.TabbedThumbnail.SetThumbnailClip(this.Handle, new Rectangle((int)v.X, (int)v.Y, (int)mediaElement1.RenderSize.Width, (int)mediaElement1.RenderSize.Height));
        }

Developing for Windows 7: Taskbar #4: Taskbar Preview Buttons:

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            tbbPlay = new ThumbnailToolBarButton(icon_play, "Play");
            tbbPlay.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(button_play_Click);

            tbbPause = new ThumbnailToolBarButton(icon_pause, "Pause");
            tbbPause.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(button_pause_Click);

            tbbStop = new ThumbnailToolBarButton(icon_stop, "Stop");
            tbbStop.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(button_stop_Click);

            TaskbarManager.Instance.ThumbnailToolBars.AddButtons(new WindowInteropHelper(this).Handle, tbbPlay, tbbPause, tbbStop);
        }
        //I just renamed button1/2/3 click events.. Note changed to "EventArgs e" from "RoutedEventArgs e".
        private void button_play_Click(object sender, EventArgs e)
        {
            taskbar.SetOverlayIcon(icon_play, "Playing");
            taskbar.SetProgressState(TaskbarProgressBarState.Normal);
            mediaElement1.Play();
        }
        private void button_pause_Click(object sender, EventArgs e)
        {
            taskbar.SetOverlayIcon(icon_pause, "Paused");
            taskbar.SetProgressState(TaskbarProgressBarState.Paused);
            mediaElement1.Pause();
        }
        private void button_stop_Click(object sender, EventArgs e)
        {
            taskbar.SetOverlayIcon(icon_stop, "Stopped");
            taskbar.SetProgressState(TaskbarProgressBarState.Error);
            mediaElement1.Stop();
        }

Advertisements

One Response to WindowsAPICodePack Taskbar videos

  1. Elden says:

    Thanks for the marvelous posting! I actually enjoyed reading it,
    you may be a great author.I will be sure to bookmark your blog
    and may come back from now on. I want to encourage one to continue your great writing, have a nice day!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: