Click here to Skip to main content
15,892,927 members
Articles / Programming Languages / C#

Updating Jumplists On The Fly

Rate me:
Please Sign up or sign in to vote.
4.62/5 (43 votes)
2 Feb 2010CPOL2 min read 32.1K   294   20  
This article shows the basics of using jumplists; creating tasks in them linking to another excutable and updating them on the fly.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using Microsoft.Win32;
using System.Text;
using System.Reflection;
using System.IO;
using System.Windows.Forms;
using MS.WindowsAPICodePack.Internal;
using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Taskbar;



namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private const string appId = "SportsScores";
        private const string progId = "SportsScores";

        private JumpList jumpList;

        private string executableFolder;
        private readonly string executablePath;

        // Keep a reference to the Taskbar instance
        private TaskbarManager windowsTaskbar = TaskbarManager.Instance;

        public Form1()
        {
            InitializeComponent();

            // Set the application specific id
            windowsTaskbar.ApplicationId = appId;

            // Save current folder and path of running executable
            executablePath = Assembly.GetEntryAssembly().Location;
            executableFolder = Path.GetDirectoryName(executablePath);
           
            if (timer1.Enabled == true)
                button3.Text = "Stop timer";
            else
                button3.Text = "Start timer";

            txtURL.Text = string.Format("http://www.nhl.com/ice/scores.htm?date={0:00}%2F{1:00}%2F{2}", DateTime.Today.Month, DateTime.Today.Day, DateTime.Today.Year);
            webBrowser1.Navigate(txtURL.Text);
       
        }

             

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            string[] games = ScoreList.getNHLGameList(webBrowser1.Document.GetElementsByTagName("tbody")).Split('|');
            string IEPath = "C:\\Program Files\\Internet Explorer\\";

            // clear the tasks before we loop through the games and add them as jumplist tasks

            jumpList.ClearAllUserTasks();
            foreach (string g in games)
            {

                if (!String.IsNullOrEmpty(g))
                {
                    string s = ScoreList.NHLBreakDown(g);
                    IEPath = String.Format("C:\\Program Files\\Internet Explorer\\iexplore.exe");
                    JumpListLink jll = new JumpListLink(IEPath, s);
                    jll.IconReference = new IconReference(IEPath, 0);
                    jll.Arguments = txtURL.Text;

                    jumpList.AddUserTasks(jll);

                }
            }

            jumpList.Refresh();
        }

        private void button2_Click(object sender, EventArgs e)
        {
           
            webBrowser1.Navigate(txtURL.Text);
            webBrowser1.Refresh();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            webBrowser1.Refresh();
            
            string systemFolder = Environment.GetFolderPath(Environment.SpecialFolder.System);

            jumpList.ClearAllUserTasks();

        
            jumpList.Refresh();
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            timer1.Interval = Convert.ToInt32(numericUpDown1.Value * 60000);
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            timer1.Enabled = !timer1.Enabled;
            if (timer1.Enabled == true)
                button3.Text = "Stop timer";
            else
                button3.Text = "Start timer";
        }

       

        private void Form1_Shown(object sender, EventArgs e)
        {
            string systemFolder = Environment.GetFolderPath(Environment.SpecialFolder.System);
            
            jumpList = JumpList.CreateJumpList();

            jumpList.ClearAllUserTasks();

            jumpList.Refresh();


        }

     

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions