Developing with the Taskbar in Windows 7
page 4 of 7
by Sergey Zwezdin
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 32180/ 42

Thumbnail buttons

Another interesting possibility of a new task panel in Windows 7 is the opportunity to add your own buttons to manage application in a preview window. Similar functionality can be noticed when you use Windows 7. For example, analogues buttons are in Windows Media Player. They allow us to switch tracks and stop playing. You can create more then seven such buttons.

Without a doubt, such functionality can be useful not only in Media Player, but also in our applications. Let us look at how we can implement it in our applications. Creation of our buttons should occur at the moment of WM_TaskbarButtonCreated message processing. That is why we should redefine the method WndProc on a form and process moments of this event occurrencef.

Listing 3: Overriding WndProc method

protected override void WndProc(ref Message m)
{
    if (m.Msg == Windows7Taskbar.TaskbarButtonCreatedMessage)
    {
        // initialize buttons
    } 
 
    base.WndProc(ref m);
}

ThumbButtonManager object is needed to initialize buttons. This object manages the behavior and the displaying of these buttons. This object can be created using an extension method CreateThumbButtonManager. After that, it is necessary to take advantage of CreateThumbButton method and create an object of a button. After all buttons will be created, it is necessary to add them on the task panel thanks to AddThumbButtons method.

Listing 4: Creation of the buttons

protected override void WndProc(ref Message m)
{
    if (m.Msg == Windows7Taskbar.TaskbarButtonCreatedMessage)
    {
        InitializeThumbButtons();
    }
 
    base.WndProc(ref m);
}
 
protected void InitializeThumbButtons()
{
    ThumbButtonManager thumbButtonManager = 
        WindowsFormsExtensions.CreateThumbButtonManager(this);
 
    var decreaseThumbButton = thumbButtonManager.CreateThumbButton(1, 
                        Icons.Navigation_First_2, "To reduce the progress");
    decreaseThumbButton.Clicked += delegate
                           {
                            // ..
                           };
 
    thumbButtonManager.AddThumbButtons(decreaseThumbButton);
}

Now, when you start the application you can see that there was one button control. But if we try to press it, we will see that the handler of event will not work. To let it work it is necessary to pass directly to the opportunity of process events to ThumbButtonManager object in WndProc method. As a result, we receive the following simple code.

Listing 5: Handling the pressing of buttons

private ThumbButtonManager _thumbButtonManager; 
protected override void WndProc(ref Message m)
{
    if (m.Msg == Windows7Taskbar.TaskbarButtonCreatedMessage)
    {
        InitializeThumbButtons();
    }
    
    if (_thumbButtonManager != null)
        _thumbButtonManager.DispatchMessage(ref m);
 
 
    base.WndProc(ref m);
}
 
protected void InitializeThumbButtons()
{
    if (_thumbButtonManager == null)
    {
        _thumbButtonManager = WindowsFormsExtensions.
            CreateThumbButtonManager(this);
    }
    
    var decreaseThumbButton = _thumbButtonManager.CreateThumbButton(1, 
        Icons.Navigation_First_2, "To reduce the progress");
    decreaseThumbButton.Clicked += delegate
                       {
                        Progress.Text = 
                            (float.Parse(Progress.Text) - 10).ToString();
                        WindowsFormsExtensions.SetTaskbarProgress(this, 
                            float.Parse(Progress.Text));
                       };
 
    // other buttons
 
    _thumbButtonManager.AddThumbButtons(decreaseThumbButton, 
        normalStateThumbButton, indeterminateStateThumbButton, 
        pauseStateThumbButton, errorStateThumbButton, increaseThumbButton);
}

This application contains 6 buttons to control progress.

Figure 3: Thumbnail buttons


View Entire Article

User Comments

Title: Source Code & Windows 7 Lib   
Name: Willy
Date: 2011-01-13 9:07:34 PM
Comment:
hi sergey, your article is amazing
please send me the source code, I need to improved my application, email me at skylancer3id@yahoo.com

I wonder where is download the windows 7 library for C# visual studio .net 2008, my application running on it.

many thanks.
Willy
Title: Re: Attach Full Source Code   
Name: Sergey Zwezdin
Date: 2010-03-08 12:54:15 AM
Comment:
Ashish, send me mail-request, please?
sergey@zwezdin.com
Title: Attach Full Source Code   
Name: Ashish Kumar
Date: 2010-03-07 3:26:16 AM
Comment:
hi...
please attach full source code with this article.
please.........
Title: reviews   
Name: r4 dsi
Date: 2009-11-30 5:43:34 AM
Comment:
Windows 7 is more than what Vista should have been, it's where Microsoft needed to go. How much damage Vista did and whether Windows 7 is enough for people to finally abandon Windows XP are questions that nobody has the answers to right now.
Title: Amazing !   
Name: Aamod Thakur
Date: 2009-11-06 4:15:19 AM
Comment:
Amazing Article, Very Informative.

Thanks Sergey

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-26 11:19:00 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search