Click here to Skip to main content
Licence CPOL
First Posted 3 Feb 2010
Views 47,656
Downloads 1,156
Bookmarked 163 times

Windows 7 New Features step by step in vb.net and c#

By Helmy.m | 31 Aug 2010 | Unedited contribution
Explaining all the new must have features in windows 7 to make your application look shiny and professional like the new features of the task bar and more
Prize winner in Competition "Best VB.NET article of February 2010"
1 vote, 1.5%
1

2
5 votes, 7.6%
3
10 votes, 15.2%
4
50 votes, 75.8%
5
4.83/5 - 66 votes
6 removed
μ 4.63, σa 1.33 [?]

Introduction 

This is a quick step by step guide to help all .Net developers to take advantage of the new features of Windows 7.

What you will Need 

  1. Visual Studio 2008 or 2010
  2. Windows API Code Pack for Microsoft .NET Framework Can be downloaded from http://code.msdn.microsoft.com/WindowsAPICodePack
  3. Minimum .NET Framework version required is 3.5 SP1.
  4. A Windows 7 machine.

Getting Ready  

You will need to compile the Windows API Code Pack Dlls,
after extracting the WindowsAPICodePack.zip file open the WindowsAPICodePack.sln located inside the WindowsAPICodePack folder and Build the solution
this will produce the following Dlls
* Core
* Shell (Note : it depends on the Core project )

you will need to add a Reference to them in your applications.

Compatibility with Different Versions of windows 

the application will crash and exit if for example a feature exclusive to windows 7 was called and it was running under a windows vista or a windows XP environment.

so to prevent your  application from crashing and ensure a level of compatibility with different versions of windows you will need to check for the current running version of windows .

  1. Checking the shared Boolean properties RunningOnWin7, RunningOnVista and RunningOnXP under MS.WindowsAPICodePack.Internal.CoreHelpers , you will need to add a reference to the WindowsAPICodePack\Core project source code after adding it to your soulution or its DLL.
  2. While using the TaskbarManager class as you will see it provides a simple Boolean property IsPlatformCompatible, you can use it to do a simple check before calling your code.

Now from here on you can skip to any section of this article and continue learning about the feature you like, as all the following sections of this article are independent from each other.

 

 

Jump Lists  

The right click menu of the applications Icon in the task bar has new feature called JumpLists, you will also see it in the application shortcuts in the start menu , you can add your own shortcuts in the menu and sort them in categories if you like,the shortcuts can point to anything like recent documents, frequently used documents and application functionality, its very simple to use but there are few points you need to know about it successfully use it  

  1. the application must have a valid icon in the task bar, so you cannot use the load event for example to create the new instance of the jumplist
  2. if you are going to add a file you must ensure the file association relationship to your application for example to add a "file.abc" you need to make sure the abc file type is associated with your application
  3. - you can add your items to the User tasks or the Recent Sections of the jump list or you can create your own custom categories
  4. To actually add the jumplist or update it you need to call the refresh() method in the new jumplist instance you create

JumpList1.jpg

To use the JumpLists in your own applications :

  1. add a reference to Microsoft.WindowsAPICodePack.Shell and Microsoft.WindowsAPICodePack
  2. you will be using the Microsoft.WindowsAPICodePack.Taskbar , Microsoft.WindowsAPICodePack.Shell namespaces
  3. create an instance of the JumpList class after the window has been created, that can be done using the shown event in winforms or the loaded event in WPF
  4. You can add different items to the Jump list in User tasks or the Recent Sections or create you own custom category
  5. Display the Jump List by calling the Refresh Method

VB

        Dim JList As JumpList
        JList = JumpList.CreateJumpList()
        JList.ClearAllUserTasks()


        'Add 2 Links to the Usertasks with a Separator
        Dim Link0 As New JumpListLink("cmd.exe", "Cmd") With {.IconReference = 
            New IconReference("cmd.exe", 0)}
        Dim Link1 As New JumpListLink("Calc.exe", "Calculator") With {.IconReference = 
            New IconReference("Calc.exe", 0)}
        JList.AddUserTasks(Link0)
        JList.AddUserTasks(New JumpListSeparator())
        JList.AddUserTasks(Link1)

        'Create a Custom Category and Add an Item to it 
        Dim Link2 As New JumpListLink("Notepad.exe", "Notepad") With {.IconReference = 
            New IconReference("Notepad.exe", 0)}
        Dim Category As New JumpListCustomCategory("New Category 1")
        Category.AddJumpListItems(Link2)
        JList.AddCustomCategories(Category)

        'Add another Item to the Category But separete with a separator
        Dim Link3 As New JumpListLink("mspaint.exe", "Paint") With {.IconReference = 
            New IconReference("mspaint.exe", 0)}
        Category.AddJumpListItems(Link3)

        'to control which category Recent/Frequent is displayed 
        JList.KnownCategoryToDisplay = JumpListKnownCategoryType.Frequent

        JList.Refresh()

C#

                JumpList JList = default(JumpList);
                JList = JumpList.CreateJumpList();
                JList.ClearAllUserTasks();


                //Add 2 Links to the Usertasks with a Separator
                JumpListLink Link0 = new JumpListLink("cmd.exe", "Cmd") { IconReference = 
                    new IconReference("cmd.exe", 0) };
                JumpListLink Link1 = new JumpListLink("Calc.exe", "Calculator") { 
                    IconReference = new IconReference("Calc.exe", 0) };
                JList.AddUserTasks(Link0);
                JList.AddUserTasks(new JumpListSeparator());
                JList.AddUserTasks(Link1);

                //Create a Custom Category and Add an Item to it
                JumpListLink Link2 = new JumpListLink("Notepad.exe", "Notepad") { 
                    IconReference = new IconReference("Notepad.exe", 0) };
                JumpListCustomCategory Category = new JumpListCustomCategory(
                    "New Category 1");
                Category.AddJumpListItems(Link2);
                JList.AddCustomCategories(Category);

                //Add another Item to the Category But separete with a separator
                JumpListLink Link3 = new JumpListLink("mspaint.exe", "Paint") {
                    IconReference = new IconReference("mspaint.exe", 0) };
                Category.AddJumpListItems(Link3);

                //to control which category Recent/Frequent is displayed
                JList.KnownCategoryToDisplay = JumpListKnownCategoryType.Frequent;

                JList.Refresh();

The last thing to note about the Jumplists is that you can add commands to the jumplists that will execute in your running application, for example to add a "play song" or "new document", but there's no Simplified or direct way to do that in the API code pack or in the .net framework, to add a Command you can add an item to the jump list that points back to your application and adding a command line argument that will be passed to your application, this will run another instance of your applications and pass the command line argument to it, what you will need to do next is if a command was passed to the application it will need to send it to first instance of the application, that's called inter-process communication, or IPC and there are multiple ways to implement this, For instance you could be using memory-mapped files, TCP/IP sockets, or named kernel objects. One option is to use named pipes, which provide a straightforward way to send messages without changing security or firewall settings, but that's another subject outside the scope of this article, and I'm sure you will find many articles here in code project that covers this.

 

 

Icon Overlay

This new feature of Windows7 will give you the ability to update the icon of the application itself shown in the task bar with overlays you can use it to indicate a status change or an error, for example you can do that by overlaying a smaller icon and it will be placed in the lower right corner of the main window icon to indicate the status of the application. 

IconOverlay1.jpg

To use the Task Bar Icon Overlay you need to

  1. add a reference to Microsoft.WindowsAPICodePack.Shell and Microsoft.WindowsAPICodePack
  2. you will be using the Microsoft.WindowsAPICodePack.Taskbar and Microsoft.WindowsAPICodePack.Shell namespaces
  3. to change the overlay Icon
    TaskbarManager.Instance.SetOverlayIcon(Icon, "accessibility text")

The SetOverlayIcon method accepts System.Drawing.Icon object and a text for accessibility

I'd like to mention the "StockIcon" class in the API code pack, this class can be used to return an icon from the system icons
StockIcon constructor accepts 4 parameters

  1. An enum value to a very large collection of stock icons
  2. The icon size, this will not change the size of the icon on the overlay but rather the returned icon itself as some icons has more than 1 bitmap for different sizes
  3. IsLink a Boolean that if true will display a small shortcut arrow on the return icon
  4. IsSelected a Boolean that dimes the returned icon a bit to indicate a selected state

VB

Dim ID As StockIconIdentifier =StockIconIdentifier.Shield
Dim Size As StockIconSizes =ShellSize
Dim SelectedIcon As New Microsoft.WindowsAPICodePack.Shell.StockIcon(ID, Size, false,
    false)
TaskbarManager.Instance.SetOverlayIcon(Me.Handle, SelectedIcon.Icon, "Icon Name")

C#

    StockIconIdentifier ID = StockIconIdentifier.Shield;
    StockIconSizes Size = ShellSize;
    Microsoft.WindowsAPICodePack.Shell.StockIcon SelectedIcon =
        new Microsoft.WindowsAPICodePack.Shell.StockIcon(ID, Size, false, false);
    TaskbarManager.Instance.SetOverlayIcon(this.Handle, SelectedIcon.Icon, "Icon Name");

IconOverlays2.png

 

Progress Bar 

ProgressBar2.png

The area for each application icon in the windows 7 task bar provides new functionality, if you download a file using Internet Explorer 8 you will notice the icon background can act as a progress bar,


To use the Task Bar Progress Bar you need to

  1. add a reference to Microsoft.WindowsAPICodePack.Shell and  Microsoft.WindowsAPICodePack
  2. you will be using the Microsoft.WindowsAPICodePack.Taskbar namespace
  3. to set the progress bar value
    TaskbarManager.Instance.SetProgressValue(Value, Maximum , handle )

    the SetProgressValue accepts the value and the max value and a handle to the window to show the progressbar on

  4. to change the state of the progress bar
TaskbarManager.Instance.SetProgressState

The SetProgressState accepts a single enum parameter (TaskbarProgressBarState) and it has the values :

  • NoProgress : No progress is displayed.
  • Indeterminate : The progress is indeterminate (marquee)
  • Normal : Normal progress is displayed (Green)
  • Error : Error progress bar (Red)
  • Paused : Paused progress bar (Yellow) note that all it dose is change the color to yellow if you change the value of the progress bar it will move and it will stay yellow

also note that if you change the value of the progress bar after setting the state to NoProgress or indeterminate the progress bar will go back to normal state automatically

ProgressBar3.png

Very important point:
Both methods for setting the value or changing the state of the progress bar has 2 overloads the second one lets you select the window you want to show the progress bar on, if you didn't set the window handle the progress bar will be shown on the main application icon in the task bar and not on the open window with the progress bar.

Another effect of not passing the window handle is when the progress window closes the progress bar will not automatically clear from the main application icon, and you will have to clear it manually, to understand it clearly right click the task bar > properties > and set the task bar buttons to never combine, and then experiment with my source code provided with this article to see the difference between passing the window handle or not.

ProgressBar4.png

 

Thumbnail Tool Bars


Thumbnailtoolbars1.png

Thumbnail Tool bars enables users to access the application’s functionality even when the application is not in focus, or the application window is behind another window making it not visible on the screen,
it enables you to access to the application without the need to switch to it and make it the active window.
open "windows media player" to see a very good example of the thumbnail toolbars functionality 

To able to add buttons to the thumbnail tool bars There are some rules to follow

  • A - you are only limited by up to 7 buttons with the size of 16 x 16 pixels
  • B - you can only hide a button after it has been added , you cannot add or delete buttons after task bar icon is shown

    To add Thumbnail toolbars you need to

    1. Create an instance of the buttons you would like to add using the ThumbnailToolbarButton
    2. Add the button to the Thumbnail toolbars by calling TaskbarManager.Instance.ThumbnailToolbars.AddButtons method, this method will take the window handle you like to add the ThumbnailToolbar Buttons to and the Buttons instance you like to add

VB

    Dim B1Icon As Icon = New StockIcon(StockIconIdentifier.Shield).Icon
    Dim B2Icon As Icon = New StockIcon(StockIconIdentifier.Users).Icon
    Dim B3Icon As Icon = New StockIcon(StockIconIdentifier.Help).Icon

    Dim button1 As New ThumbnailToolbarButton(B1Icon, "First Button")
    Dim WithEvents button2 As New ThumbnailToolbarButton(B2Icon, "Second Button")
    Dim WithEvents button3 As New ThumbnailToolbarButton(B3Icon, "Third Button")

    AddHandler button1.Click, AddressOf Button_Click
    AddHandler button2.Click, AddressOf Button_Click
    AddHandler button3.Click, AddressOf Button_Click

    'You can show or hide the buttons
    button1.Visible = Not button1.Visible

    'You can enable or disable the buttons
    button2.Enabled = Not button2.Enabled

    'And you can chnage the button tool tip text
    button3.Tooltip = txtTooltip.Text

    Sub Button_Click(ByVal sender As Object, ByVal e As ThumbnailButtonClickedEventArgs) 
        Me.EventsList.Items.Add(e.ThumbnailButton.Tooltip & " Clicked")
    End Sub

C#

Icon B1Icon  = new StockIcon(StockIconIdentifier.Shield).Icon;
Icon B2Icon  = new StockIcon(StockIconIdentifier.Users).Icon;
Icon B3Icon  = new StockIcon(StockIconIdentifier.Help).Icon;
ThumbnailToolbarButton button1 = 
    new Microsoft.WindowsAPICodePack.Taskbar.ThumbnailToolbarButton (B1Icon,
    "First Button");
ThumbnailToolbarButton button2 =
    new Microsoft.WindowsAPICodePack.Taskbar.ThumbnailToolbarButton(B2Icon,
    "Second Button");
ThumbnailToolbarButton button3 =
    new Microsoft.WindowsAPICodePack.Taskbar.ThumbnailToolbarButton(B3Icon,
    "Third Button");

button1.Click += button_Click;
button2.Click += button_Click;
button3.Click += button_Click;

TaskbarManager.Instance.ThumbnailToolbars.AddButtons(this.Handle,button1,button2,button3);

//You can show or hide the buttons
 button1.Visible = !button1.Visible;

//You can enable or disable the buttons
button2.Enabled = !button2.Enabled;

//And you can chnage the button tool tip text
button3.Tooltip = txtTooltip.Text;

Thumbnailtoolbars2.png

 

Network Management 

you can use it to know if the computer your application is working on has a network connection or not, if it is connected to the internet, retrive the network name, if you are on a domain and get the NetworkID and more

To make use of the Network Managment APIs you need to

  1. add a reference to Microsoft.WindowsAPICodePack the Core Project only
  2. you will be using the Microsoft.WindowsAPICodePack.Net namespace
  3. To list all the available networks call the  NetworkListManager.GetNetworks() method it accepts enum 1 parameter
    All : to return all networks connected and disconnected

    Connected : to return only the connected networks
    Disconnected : to return only the disconnected network

  4. you can enumerate throw the returned networks list to get information about all the networks, information like  the NetworkID (Thats the GUID of the Network interface), the network name , the network description , if its a domain or not , the time this network connection was created and the time it was connected and all the available connections under this network. 

VB

        Dim networks As NetworkCollection = NetworkListManager.GetNetworks(
            NetworkConnectivityLevels.All)
        For Each n As Network In networks

            Dim network As Network = n
            txtName.Text = network.Name
            txtDecription.Text = network.Description
            txtDomainType.Text = network.DomainType.ToString()
            chkIsConnected.Checked = network.IsConnected
            chInternet.Checked = network.IsConnectedToInternet
            txtCategory.Text = network.Category.ToString()
            txtCreatedTime.Text = network.CreatedTime.ToString()
            txtConnectedTime.Text = network.ConnectedTime.ToString()
            txtConnectivity.Text = network.Connectivity.ToString()
            Dim Connections As NetworkConnectionCollection = network.Connections

            For Each Connection As NetworkConnection In network.Connections
                lstConnections.Items.Add("ConnectionID: " & 
                    Connection.ConnectionId.ToString)
                lstConnections.Items.Add("Adapter ID:: " & Connection.AdapterId.ToString)
            Next
        End If

        Next

C#

         NetworkCollection networks = NetworkListManager.GetNetworks(
             NetworkConnectivityLevels.All);

         foreach (Network n in networks) {
             Network network = n;
             txtName.Text = network.Name;
             txtDecription.Text = network.Description;
             txtDomainType.Text = network.DomainType.ToString();
             chkIsConnected.Checked = network.IsConnected;
             chInternet.Checked = network.IsConnectedToInternet;
             txtCategory.Text = network.Category.ToString();
             txtCreatedTime.Text = network.CreatedTime.ToString();
             txtConnectedTime.Text = network.ConnectedTime.ToString();
             txtConnectivity.Text = network.Connectivity.ToString();
             NetworkConnectionCollection Connections = network.Connections;

             foreach (NetworkConnection Connection in network.Connections) {
                 lstConnections.Items.Add("ConnectionID: " + 
                     Connection.ConnectionId.ToString);
                 lstConnections.Items.Add("Adapter ID:: " +
                     Connection.AdapterId.ToString);
             }
        }

NetworkInfo.png

License

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

About the Author

Helmy.m

Software Developer
IDS
United States United States

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionTitleBar Button PinmemberPaul van der Stel9:00 30 Jan '12  
QuestionNice article Pinmemberderek99994:14 11 Jan '12  
GeneralMy vote of 5 Pinmembersarthakganguly21:30 20 Aug '11  
GeneralMy vote of 5 PinmemberEddy Vluggen1:46 4 Jan '11  
GeneralSetOverlayIcon doesn't work on my machine Pinmembern0name206:33 11 Dec '10  
GeneralIsPlatformSupported PinmemberAlessandro Bernardi12:57 1 Dec '10  
GeneralMy vote of 5 PinmemberAlessandro Bernardi11:57 1 Dec '10  
GeneralMy vote of 5 Pinmemberdbaileychess19:32 14 Nov '10  
QuestionWould it be possible to add the new stuff? PinmemberSimon Dufour6:48 20 Sep '10  
AnswerRe: Would it be possible to add the new stuff? PinmemberHelmy.m2:46 2 Oct '10  
GeneralVery nice examples Pinmemberbhiller5:19 9 Sep '10  
GeneralCould be better PinmemberSimon Dufour3:41 26 Aug '10  
GeneralRe: Could be better PinmemberHelmy.m23:01 31 Aug '10  
GeneralRe: Could be better PinmemberSimon Dufour1:34 1 Sep '10  
GeneralRe: Could be better PinmemberHelmy.m2:25 1 Sep '10  
GeneralRe: Could be better PinmemberSimon Dufour4:51 1 Sep '10  
GeneralPreventing app from creating new taskbar button when launched PinmemberJohnAndre9:00 11 May '10  
QuestionWhere did you get Client rofile download? PinmemberMember 383892813:47 22 Mar '10  
GeneralNice approach PinmemberHristo Bojilov6:32 7 Feb '10  
GeneralExcelent work Pinmemberj.avery10:59 5 Feb '10  
GeneralMy vote of 1 PinmemberBooGhost9:06 5 Feb '10  
GeneralRe: My vote of 1 Pinmemberoddessa376:04 8 Mar '10  
QuestionAny chance for .Net 2.0? Pinmemberz00z05:24 5 Feb '10  
AnswerRe: Any chance for .Net 2.0? PinmemberHelmy.m18:12 5 Feb '10  
GeneralRe: Any chance for .Net 2.0? Pinmemberz00z022:12 5 Feb '10  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120209.1 | Last Updated 1 Sep 2010
Article Copyright 2010 by Helmy.m
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid