Click here to Skip to main content
15,893,668 members
Articles / Programming Languages / C#
Tip/Trick

Custom (XP-like) QuickLaunch

Rate me:
Please Sign up or sign in to vote.
4.33/5 (2 votes)
4 Oct 2013CPOL1 min read 11.1K   7   1
An easy implementation of the taskbar-independent "quick launch"

Introduction

In times of Windows XP I liked having my desktop just for the data I worked with and my application launchers (lots of them) separately at the right side of the screen.

Since Windows Vista (AFAIK), there is no way how to drag the "quick launch" out of the taskbar and drop it elsewhere. First, I tried to search for any freeware/shareware that would simulate the XP "quick launch" behaviour. I haven't found anything similar (just taskbar-bound gadgets or floating panels with animations which I didn't like). So I decided to write one. I don't include a complete downloadable application, just a framework how to create it in a very easy way.

Using the code

  1. Sort your desktop icons according to the type and move the shortcuts (.lnk files) to a folder (e.g., C:\Users\John Doe\Documents\Panel).
  2. Create Windows forms application. I suggest these Form1 properties:
  3. C#
    FormBorderStyle = FixedToolWindow
    StartPosition = Manual
    MaximizeBox = False
    MinimizeBox = False
    ShowInTaskbar = False

    Set the Text, Size, and Location according to your needs.

  4. Drop a ListView onto a form and dock it to fill it. I suggest these listView1 properties:
  5. C#
    HeaderStyle = None
    Dock = Fill   
    HoverSelection = True
    HotTracking = True
    Activation = OneClick

    Set the BackColor, Font, and ForeColor according to your needs.

  6. Switch to the code. Put this code into the constructor of the Form1.
  7. C#
    public Form1()
    {
        InitializeComponent();
    
        // needed for displaying View.Details
        listView1.Columns.Add("Shortcut", -2);
    
        // get collection of the shortcut paths
        string[] files = Directory.GetFiles(@"C:\Users\John Doe\Documents\Panel");
        ImageList ilSmall = new ImageList();
        
        // extract the shorcut icons
        foreach (string fp in files)
        {
            ilSmall.Images.Add(IconFromFilePath(fp));
        }
        listView1.SmallImageList = ilSmall;
        listView1.View = View.Details;
    
    
        int iIdx = 0;
        // feed the listView1
        foreach (string file in files)
        {
            // display just the filename
            string fileName = Path.GetFileNameWithoutExtension(file);
            ListViewItem item = new ListViewItem(fileName);
            // store the complete path
            item.Tag = file;
    
    
            listView1.Items.Add(item);
            // set the index of the icon
            item.ImageIndex = iIdx++;
        }
    }
  8. Implement some more methods/handlers.  
  9. C#
    /// <summary>
    /// Extracts the shell icon of the executable, shortcut, document...
    /// </summary>
    /// <param name="filePath">Path</param>
    /// <returns>An Icon instance</returns>
    private Icon IconFromFilePath(string filePath)
    {
        Icon result = null;
        try
        {
            result = Icon.ExtractAssociatedIcon(filePath);
        }
        catch { }
    
        return result;
    }
    
    /// <summary>
    /// Prevent the window from unwanted closing
    /// (Form1 FormClosing event handler)
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (MessageBox.Show("Really quit?", "Confirm",
               MessageBoxButtons.YesNo, MessageBoxIcon.Question) != 
               System.Windows.Forms.DialogResult.Yes)
            e.Cancel = true; 
    }
    
    /// <summary>
    /// Launch the shortcut (or executable, document...)
    /// (listView1 ItemActivate event handler)
    /// (the same code can handle listView1 DoubleClick event, if preferred)
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void listView1_ItemActivate(object sender, EventArgs e)
    {
        ListViewItem lvi = listView1.SelectedItems[0];
        Process proc = new Process();
        
        // If the application does not start, check the shortcut.
        // There could be Program Files (x86) issue, the incorrect executable path set.
        try
        {
            // extract the stored file path
            proc.StartInfo.FileName = (string)lvi.Tag;
            proc.Start();
        }
        catch { }
    }  
  10. Compile the application and put the executable to your Startup folder. Log off, log on and enjoy!

License

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


Written By
Software Developer (Senior)
Czech Republic Czech Republic
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralDownload link Pin
Adam Wojnar3-Oct-13 3:21
Adam Wojnar3-Oct-13 3:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.