Click here to Skip to main content
13,902,437 members
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 12 Mar 2010
Licenced Ms-PL

Windows 7 Taskbar C# Quick Reference

, 14 Mar 2010
Rate this:
Please Sign up or sign in to vote.
Following are some listings to be used as a quick reference to common Windows 7 Taskbar features using Windows API Code Pack.

Following are some listings to be used as a quick reference to common Windows 7 Taskbar features using Windows API Code Pack.

The code in this post is based on previous work by Yochay and Sasha.


Setting the process Application ID

TaskbarManager.Instance.ApplicationId = "TaskbarManaged";

Note: This should be done before the window is shown, a good place is on form load.

Setting the Application ID of a window

TaskbarManager.Instance.SetApplicationIdForSpecificWindow(form.Handle, "SomethingElse");

or in WPF:

TaskbarManager.Instance.SetApplicationIdForSpecificWindow(wpfWindow, "SomethingElse");

Adding a file into the Recent category on the JumpList

_jumpList = JumpList.CreateJumpList();



Note: You must register (associate) the file type with your application for this to work. Note 2: If you use the common dialogs to open a file it will get added automatically to the recent list.

Adding tasks to the JumpList

IJumpListTask task1 = new JumpListLink(filePath, taskTitle)
    Arguments = arguments,
    WorkingDirectory = workingDirectory

IJumpListTask separator = new JumpListSeparator();
IJumpListTask task2 = ...

_jumpList.AddUserTasks(task1, separator, task2);

Adding custom categories

JumpListCustomCategory category = new JumpListCustomCategory("My Category");

IJumpListItem item1 = new JumpListLink(path1, title1);
IJumpListItem item2 = new JumpListLink(path2, title2);

category.AddJumpListItems(item1, item2);

Creating Thumbnail Toolbars

ThumbnailToolbarButton button1 = new ThumbnailToolbarButton(icon, tooltip);
button1.Click += delegate
    MessageBox.Show("button1 clicked");

TaskbarManager.Instance.ThumbnailToolbars.AddButtons(form.Handle, button1);

Setting Overlay Icon

TaskbarManager.Instance.SetOverlayIcon(icon, accessibilityText);

Setting Progress State and Value

TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal, form.Handle);
TaskbarManager.Instance.SetProgressValue(currentValue, maximumValue, form.Handle);

Customizing Live Thumbnail

TabbedThumbnail preview = new TabbedThumbnail(parentForm.Handle, childForm.Handle);
preview.TabbedThumbnailBitmapRequested += (o, e) =>
        Bitmap bmp = new Bitmap(width, height);
        // draw custom bitmap...
        e.Handled = true;

Extra Notes

A drawback in Windows API Code Pack v1.0.1

When using the Windows API Code Pack library to add Taskbar features to your WinForms application you must add a references to the following WPF DLLs: PresentationCore.dll, PresentationFramework and WindowsBase.dll

The reason is that every Taskbar function in the library that has an handle in its arguments comes in pair, the first expects a native IntPtr (used with myWinForm.Handle property) and the second expects a WPF Window object. Since we use a class that expects WPF types in its arguments (Taskbar) we must add the WPF DLLs to our WinForms project.

A Bug in Windows API Code Pack v1.0.1

ThumbnailToolbarButton Click event isn’t fired when process is running elevated (i.e. as Administrator)

The problem is that some of the taskbar messages doesn’t pass thru the Windows UIPI mechanism. A quick fix is to add the following line to the load event:

private void Form_Load(object sender, EventArgs eventargs)

The definition of this method is brought here:

#region Fix bug in Windows API Code Pack

[DllImport("user32.dll", EntryPoint = "RegisterWindowMessage", SetLastError = true,
    CharSet = CharSet.Unicode)]
private static extern uint RegisterWindowMessage([MarshalAs(
    UnmanagedType.LPWStr)] string lpString);

[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr ChangeWindowMessageFilter(uint message, uint dwFlag);

private const uint MSGFLT_ADD = 1;
private const uint WM_COMMAND = 0x0111;
private const uint WM_SYSCOMMAND = 0x112;
private const uint WM_ACTIVATE = 0x0006;

/// <span class="code-SummaryComment"><summary>
</span>/// Specifies that the taskbar-related windows messages should
/// pass through the Windows UIPI mechanism even if the process is
/// running elevated. Calling this method is not required unless the
/// process is running elevated.
/// <span class="code-SummaryComment"></summary>
</span>private static void AllowTaskbarWindowMessagesThroughUIPI()
    uint WM_TaskbarButtonCreated = RegisterWindowMessage("TaskbarButtonCreated");

    ChangeWindowMessageFilter(WM_TaskbarButtonCreated, MSGFLT_ADD);
    ChangeWindowMessageFilter(WM_COMMAND, MSGFLT_ADD);
    ChangeWindowMessageFilter(WM_SYSCOMMAND, MSGFLT_ADD);
    ChangeWindowMessageFilter(WM_ACTIVATE, MSGFLT_ADD);

#endregion Fix bug in Windows API Code Pack

That’s it for now,
Arik Poznanski.


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Arik Poznanski
Software Developer (Senior) Verint
Israel Israel
Arik Poznanski is a senior software developer at Verint. He completed two B.Sc. degrees in Mathematics & Computer Science, summa cum laude, from the Technion in Israel.

Arik has extensive knowledge and experience in many Microsoft technologies, including .NET with C#, WPF, Silverlight, WinForms, Interop, COM/ATL programming, C++ Win32 programming and reverse engineering (assembly, IL).

You may also be interested in...

Comments and Discussions

BugWindows API Code Pack 1.1 usage change (i think) Pin
Andreas Coroiu1-Apr-14 4:09
memberAndreas Coroiu1-Apr-14 4:09 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190306.1 | Last Updated 14 Mar 2010
Article Copyright 2010 by Arik Poznanski
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid