Results 1 to 6 of 6
  1. #1
    timeshift's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Rio Grande do Sul, Brasil
    Posts
    158
    Reputation
    8
    Thanks
    384
    My Mood
    Breezy

    Use the power of Windows 7 Taskbar

    THE DOWNLOADS ARE AT THE END OF THE POST!

    Each minimised application icon can been overlaid with custom icons or alpha-blended progress bars, providing the user with visual clues to the applications state. As each icon is hovered over, it can present a thumbnail image of the current user interface. If the application has the latest multi-tabbed style of user interface, each tab can presented as its own preview thumbnail. A preview thumbnail can have a mini toolbar giving access to core application functionality without the need for the user to open the application further.



    Right-clicking a minimised application taskbar icon also provides a new context menu in Windows 7. These are called Jump Lists. A jump list will contain a list of recently used files if the application has a file type associated with it. The application developer can add to the jump list custom task items to provide more short-cuts to application functionality.



    These small application enhancements soon become second nature to users, who quickly expect modern applications to deliver them. For the .NET managed code application this is easily achieved by using the Windows API Code Pack.

    The Windows 7 API Code Pack makes it easy to implement support for the key Windows 7 native features by providing a .Net managed code wrapper around the native API.

    Adding thumbnail previews
    With the help of the Windows 7 API Code Pack adding individual thumbnails is very trivial, so let’s look at how to implement thumbnail previews for a tabbed application UI. We’ll add to each thumbnail preview some buttons to control our application directly from the preview thumbnail. The code pack framework is provided as a static library built with .Net 3.5 SP1 to use the Windows API Code Pack.

    We’ll use a simple C# Winforms project to test this all out. We need to add some code pack references:

    Code:
    Microsoft.WindowsAPICodePack
    Microsoft.WindowsAPICodePack.Shell
    The code pack framework provides integration to the Windows 7 thumbnail preview via the TaskbarManager class. The class contains four methods and five properties. The methods mainly deal with the overlay of icons onto the taskbar icon and the progress bar overlay.

    To add our application specific thumbnail previews we define a TabbedThumbnail for each of our previews and add it to the TaskBar’s TabbedThumbnail collection. This collection is accessible from the Instance object of the TaskbarManager class. The Instance object represents the Windows 7 task bar.

    Code:
    // Add a new preview 
    TabbedThumbnail preview = new TabbedThumbnail(this.Handle, newTab.Handle);
    Events from the user’s interaction with the thumbnail previews are easily trapped by adding our own event handlers.

    Code:
    // Event handlers for this preview 
    preview.TabbedThumbnailActivated += new EventHandler<TabbedThumbnailEventArgs>(preview_TabbedThumbnailActivated); 
    preview.TabbedThumbnailClosed += new EventHandler<TabbedThumbnailEventArgs>(preview_TabbedThumbnailClosed); 
    preview.TabbedThumbnailMaximized += new EventHandler<TabbedThumbnailEventArgs>(preview_TabbedThumbnailMaximized); 
    preview.TabbedThumbnailMinimized += new EventHandler<TabbedThumbnailEventArgs>(preview_TabbedThumbnailMinimized);
    Now our preview thumbnail can be added to the task bar’s TabbedThumbnail collection.

    Code:
    TaskbarManager.Instance.TabbedThumbnail.AddThumbnailPreview(preview);
    Each of our application’s tab pages can have an individual preview window added by defining its own TabbedThumbnail and adding it to the TabbedThumbnail collection in this manner.

    Adding toolbars to thumbnail previews
    There is a second collection on the Instance object which enables toolbars to be added to each thumbnail preview. The ThumbnailToolbars collection accepts a toolbar definition. The definition is made by defining thumbnail toolbar buttons, their event handlers and adding them as a tool bar associated with a specified windows handle.

    Thumbnail button definitions made at class level

    Code:
    private ThumbnailToolbarButton thumbButtonBack;
    private ThumbnailToolbarButton thumbButtonForward;
    private ThumbnailToolbarButton thumbButtonRefresh;
    Thumbnail button handler assignment made at form initialisation

    Code:
    // Create our Thumbnail toolbar buttons for the Browser doc
    thumbButtonBack = new ThumbnailToolbarButton(Properties.Resources.prevArrow, "Back");
    thumbButtonBack.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(thumbButtonBack_Click);
    thumbButtonForward = new ThumbnailToolbarButton(Properties.Resources.nextArrow, "Forward");
    thumbButtonForward.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(thumbButtonForward_Click);
    thumbButtonRefresh = new ThumbnailToolbarButton(Properties.Resources.refresh, "Refresh");
    thumbButtonRefresh.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(thumbButtonRefresh_Click);
    Thumbnail toolbar defined and added to the ThumbnailToolbars collection

    Code:
    // Add thumbnail toolbar buttons 
    TaskbarManager.Instance.ThumbnailToolbars.AddButtons(newTab.Handle, thumbButtonBack, thumbButtonForward, thumbButtonRefresh);
    The end result looks like this:



    There are all sorts of additional goodies in the TabbedThumbnail class properties that allow you to clip the bitmap and effectively zoom into it as well as provide tooltips etc.

    To enable applications to run on legacy Windows versions a boolean flag – IsPlatformSupported – is provided on the TaskbarManager to indicate if the current platform can support thumbnails.

    Adding thumbnail previews to your applications is a small effort for achieving one of the most visible enhancements in the Windows 7 UI. The code pack API makes it easy to do. The complete application can be downloaded from here. It is a simplified version of the code pack Thumbnail sample.

    Adding a jump list
    After thumbnail previews the next item you’ll be looking to implement for your application is a Jumplist. A Jumplist may provide shortcuts to recent documents; frequently use documents and application functionality.

    Setting up a jumplist for your application is as simple as simple can be using the code pack managed API – but there are some gotchas worth noting.

    1. The app needs a valid active window on the taskbar before you can create a jumplist. This isn’t obvious – except when you get the code pack’s error message on first run of your modified application. Remember, in working with the new Taskbar features, we are actually providing the Taskbar with details we want it to attribute to our application. If it doesn’t know about our application, it can’t take our details.
    2. The code pack API does a good job of proactive error detection. For example, it’ll test to make sure the file you want to list on your jumplist exists. If it doesn’t we get blown out before we get near the Taskbar. This is the same with file associations. The code pack tests for the file association relationship to our application. If it doesn’t we can’t list the file. For more details on this one, look at the code pack TaskBarDemo sample. You might wonder why this extreme protection. The answer lines in the third gotcha.
    3. The known category types (Recent, Frequent) are populated by the Taskbar for our application ‘automagically’. So we only have to choose to show one of these categories in your jumplist to get the information displayed. This is because Windows maintains a recent items history infrastructure when we use the current common file dialogs. If you don’t use them (why?), we can hand code this mechanism by using the shell API SHAddToRecentDocs or the code pack’s jumplist.AddToRecent method.
    4. The code pack’s jumplist does a lot of good stuff. This includes maintaining our jumplist against the removed items list created by the user. We may want to have all the items in the jumplist but the user can selectively remove file references from our list. It’s considered bad form to keep putting the item back when the user has removed it; jumplist ensures we don’t make this mistake. If we don’t use jumplist we have to check the removedDestinations property and modify the list ourself.
    5. Now let us look at the code. Below are the specific parts of a C# Winforms application showing the creation of a jumplist.



    At class level we define the key elements of our jumplist – the jumplist variable itself and two custom categories.

    Code:
    public partial class Form1 : Form 
    { 
        private JumpList jumpList; 
    
        private JumpListCustomCategory category1 = new JumpListCustomCategory("Custom Stuff"); 
        private JumpListCustomCategory category2 = new JumpListCustomCategory("Custom Stuff2");
    All the work is kicked off in the form’s Shown event with the creation of a jumplist. Two custom categories are added to it then some tasks are added that open other applications. The jumplist is ‘published’ by calling jumplist.refresh();
    Code:
        private void Form1_Shown(object sender, EventArgs e) 
        { 
            // create a new taskbar jump list for the main window 
            jumpList = JumpList.CreateJumpList(); 
    
            // Add custom categories 
            jumpList.AddCustomCategories(category1, category2); 
    
            AddTasks(); 
            jumpList.Refresh(); 
        }
    The helper routine AddTasks is used to contain all the task definition code.

    Code:
        private void AddTasks() 
        { 
            // Path to Windows system folder 
            string systemFolder = Environment.GetFolderPath(Environment.SpecialFolder.System); 
    
            // Add our user tasks 
            jumpList.AddUserTasks(new JumpListLink(Path.Combine(systemFolder, "notepad.exe"), "Open Notepad") 
            { 
                IconReference = new IconReference(Path.Combine(systemFolder, "notepad.exe"), 0) 
            }); 
    
            jumpList.AddUserTasks(new JumpListLink(Path.Combine(systemFolder, "mspaint.exe"), "Open Paint") 
            { 
                IconReference = new IconReference(Path.Combine(systemFolder, "mspaint.exe"), 0) 
            }); 
    
            jumpList.AddUserTasks(new JumpListSeparator()); 
    
            jumpList.AddUserTasks(new JumpListLink(Path.Combine(systemFolder, "calc.exe"), "Open Calculator") 
            { 
                IconReference = new IconReference(Path.Combine(systemFolder, "calc.exe"), 0) 
            }); 
    
    
        }
    Our jump list now looks like this:



    Remember the Jumplist is created by the Taskbar for your application. Unlike the Thumbnail preview toolbars there doesn’t appear to be a mechanism of capturing jumplist events into your application. The only event raised by jumplist is when items have been removed from the jumplist since the last jumplist refresh occurred. This means achieving something similar to Internet Explorer 8’s Open new tab jumplist task, requires an ‘external’ communication to occur with our application.

    How to use Windows 7 Progress Bar

    Designer
    All you need to do is drag the Windows7ProgressBar control to the form and set the properties that apply to you:


    Add at runtime
    If you're going to be adding a Windows 7 Progress Bar at runtime you must set the Windows7ProgressBar.ContainerControl property to the owner form. For example:

    Code:
    public Form1()
    {
        Font = SystemFonts.MessageBoxFont;
    
        InitializeComponent();
    
        // create the new progres bar
        Windows7ProgressBar pBar = new Windows7ProgressBar(this);
    
        // or:
        // Windows7ProgressBar pBar = new Windows7ProgressBar();
        // pBar.ContainerControl = this;
    
        //TODO: set the size & position properties
    
        this.Controls.Add(pBar);
    }
    A post about when to use the correct type of progress bar: https://msdn.microsof*****m/en-us/libr...6(loband).aspx

    Sources: Tap into the power of the Windows 7 Taskbar - Windows 7 tutorial - developer Fusion
    How to use Windows 7 Progress Bar, open source C# control, .NET

    Windows 7 API Code Pack Download: Windows® API Code Pack for Microsoft® .NET Framework - Release: Windows API Code Pack 1.1

    Windows 7 ProgressBar DLL: In the attachment

    The Windows 7 Progressbar zipped file contains demos for both C# and VB.net and also includes the .DLL you need to use in your projects.

    <b>Downloadable Files</b> Downloadable Files
    Last edited by timeshift; 01-26-2012 at 10:44 AM.

  2. The Following User Says Thank You to timeshift For This Useful Post:

    haiqalsj (06-24-2015)

  3. #2
    Jorndel's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    Norway
    Posts
    8,676
    Reputation
    905
    Thanks
    19,113
    My Mood
    Angelic
    NICE.
    This is very nice indeed.
    But For my working it would not be useful.
    But It looks very nice and I even wondered how it would be made.
    Thanks for showing

     
    Contributor 01.27.2012 - N/A
    Donator 07-17-2012 - Current
    Editor/Manager 12-16-12 - N/A
    Minion 01-10-2013 - 07.17.13
    Former Staff 09-20-2012 - 01-10-2013 / 07-17-2013 - Current
    Cocksucker 20-04-2013 - N/A

  4. #3
    Thunder's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    North
    Posts
    13,773
    Reputation
    2920
    Thanks
    3,655

    [X]
    Crossfire minion since 06-12-2011
    Minecraft minion since 06-20-2011
    Moderator since 08-17-2011
    Global Moderator since 09-10-2011
    Super User since 08-27-2012
    [X] [X] [X]

  5. #4
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    That is pretty good. If you wrote it, then GJ

  6. #5
    tlokzz's Avatar
    Join Date
    Jan 2009
    Gender
    male
    Location
    Riverdale, CA
    Posts
    26
    Reputation
    10
    Thanks
    7
    My Mood
    Inspired
    Nice, the other day I had to use the WindowsAPICodePack.Shell for the Taskbar progress. This tut showed me what else is available to play with. Good work.

  7. #6
    brhvitor6's Avatar
    Join Date
    Apr 2012
    Gender
    male
    Posts
    16
    Reputation
    10
    Thanks
    57
    My Mood
    Amazed
    that's nice, good tutorial

Similar Threads

  1. Programming An Ipod Touch Using The Windows Platform
    By radnomguywfq3 in forum C++/C Programming
    Replies: 11
    Last Post: 04-17-2009, 11:10 AM
  2. [Pls dave, Fix it!!] U can't use the trainers made in CE? read this!!
    By juanitobalde in forum WarRock - International Hacks
    Replies: 4
    Last Post: 04-24-2007, 02:27 PM
  3. Hitsugaya - The power within_sig
    By EfiniRx7 in forum Art & Graphic Design
    Replies: 15
    Last Post: 03-26-2007, 08:36 PM
  4. Just in case you use the Console Administrator Hack...
    By Rocker1989 in forum Gunz General
    Replies: 9
    Last Post: 05-26-2006, 09:05 AM
  5. Can u use the gain experience hack with 1 player
    By mjt20mik in forum WarRock - International Hacks
    Replies: 7
    Last Post: 02-05-2006, 02:20 AM