Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

ITaskbarList (shell32)
 
.
Summary
Extends ITaskbarList3, the code is extracted from Windows API Code Pack source code.
Summary
Exposes methods that control the taskbar. It allows you to dynamically add, remove, and activate items on the taskbar.

C# Signature:

[ComImportAttribute()]
[GuidAttribute("c43dc798-95d1-4bea-9030-bb99e2983a1a")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
internal interface ITaskbarList4
[ComImport,
Guid("56fdf342-fd6d-11d0-958a-006097c9a090"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ITaskbarList
{
     // ITaskbarList
     [PreserveSig]
     /// <summary>
     /// Initializes the taskbar list object. This method must be called before any other ITaskbarList methods can be called.
     /// </summary>
     void HrInit();
     [PreserveSig]
     void AddTab(IntPtr hwnd);
     [PreserveSig]
     void DeleteTab(IntPtr hwnd);
     [PreserveSig]
     void ActivateTab(IntPtr hwnd);
     [PreserveSig]
     void SetActiveAlt(IntPtr hwnd);

     // ITaskbarList2
     [PreserveSig]
     void MarkFullscreenWindow(
     IntPtr hwnd,
     [MarshalAs(UnmanagedType.Bool)] bool fFullscreen);

     // ITaskbarList3
     [PreserveSig]
     void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal);
     [PreserveSig]
     void SetProgressState(IntPtr hwnd, TaskbarProgressBarStatus tbpFlags);
     [PreserveSig]
     void RegisterTab(IntPtr hwndTab, IntPtr hwndMDI);
     [PreserveSig]
     void UnregisterTab(IntPtr hwndTab);
     [PreserveSig]
     void SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore);
     [PreserveSig]
     void SetTabActive(IntPtr hwndTab, IntPtr hwndInsertBefore, uint dwReserved);
     [PreserveSig]
     HResult ThumbBarAddButtons(
     IntPtr hwnd,
     uint cButtons,
     [MarshalAs(UnmanagedType.LPArray)] ThumbButton[] pButtons);
     [PreserveSig]
     HResult ThumbBarUpdateButtons(
     IntPtr hwnd,
     uint cButtons,
     [MarshalAs(UnmanagedType.LPArray)] ThumbButton[] pButtons);
     [PreserveSig]
     void ThumbBarSetImageList(IntPtr hwnd, IntPtr himl);
     [PreserveSig]
     void SetOverlayIcon(
       IntPtr hwnd,
       IntPtr hIcon,
       [MarshalAs(UnmanagedType.LPWStr)] string pszDescription);
     [PreserveSig]
     void SetThumbnailTooltip(
     IntPtr hwnd,
     [MarshalAs(UnmanagedType.LPWStr)] string pszTip);
     [PreserveSig]
     void SetThumbnailClip(
     IntPtr hwnd,
     IntPtr prcClip);

     // ITaskbarList4
     void SetTabProperties(IntPtr hwndTab, SetTabPropertiesOption stpFlags);
}

VB Signature:

<ComImportAttribute> _
<GuidAttribute("c43dc798-95d1-4bea-9030-bb99e2983a1a")> _
<InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Friend Interface ITaskbarList4
    ' ITaskbarList
    <PreserveSig> _
    Sub HrInit()
    <PreserveSig> _
    Sub AddTab(hwnd As IntPtr)
    <PreserveSig> _
    Sub DeleteTab(hwnd As IntPtr)
    <PreserveSig> _
    Sub ActivateTab(hwnd As IntPtr)
    <PreserveSig> _
    Sub SetActiveAlt(hwnd As IntPtr)

    ' ITaskbarList2
    <PreserveSig> _
    Sub MarkFullscreenWindow(hwnd As IntPtr, <MarshalAs(UnmanagedType.Bool)> fFullscreen As Boolean)
     /// <summary>
     /// Adds an item to the taskbar.
     /// </summary>
     /// <param name="hWnd">A handle to the window to be added to the taskbar.</param>
     void AddTab([In] IntPtr hWnd);

    ' ITaskbarList3
    <PreserveSig> _
    Sub SetProgressValue(hwnd As IntPtr, ullCompleted As UInt64, ullTotal As UInt64)
    <PreserveSig> _
    Sub SetProgressState(hwnd As IntPtr, tbpFlags As TaskbarProgressBarStatus)
    <PreserveSig> _
    Sub RegisterTab(hwndTab As IntPtr, hwndMDI As IntPtr)
    <PreserveSig> _
    Sub UnregisterTab(hwndTab As IntPtr)
    <PreserveSig> _
    Sub SetTabOrder(hwndTab As IntPtr, hwndInsertBefore As IntPtr)
    <PreserveSig> _
    Sub SetTabActive(hwndTab As IntPtr, hwndInsertBefore As IntPtr, dwReserved As UInteger)
    <PreserveSig> _
    Function ThumbBarAddButtons(hwnd As IntPtr, cButtons As UInteger, <MarshalAs(UnmanagedType.LPArray)> pButtons As ThumbButton()) As HResult
    <PreserveSig> _
    Function ThumbBarUpdateButtons(hwnd As IntPtr, cButtons As UInteger, <MarshalAs(UnmanagedType.LPArray)> pButtons As ThumbButton()) As HResult
    <PreserveSig> _
    Sub ThumbBarSetImageList(hwnd As IntPtr, himl As IntPtr)
    <PreserveSig> _
    Sub SetOverlayIcon(hwnd As IntPtr, hIcon As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> pszDescription As String)
    <PreserveSig> _
    Sub SetThumbnailTooltip(hwnd As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> pszTip As String)
    <PreserveSig> _
    Sub SetThumbnailClip(hwnd As IntPtr, prcClip As IntPtr)
     /// <summary>
     /// Deletes an item from the taskbar.
     /// </summary>
     /// <param name="hWnd">A handle to the window to be deleted from the taskbar.</param>
     void DeleteTab([In] IntPtr hWnd);

    ' ITaskbarList4
    Sub SetTabProperties(hwndTab As IntPtr, stpFlags As SetTabPropertiesOption)
End Interface

User-Defined Types:

Do you know one? Please contribute it!

     /// <summary>
     /// Activates an item on the taskbar. The window is not actually activated; the window's item on the taskbar is merely displayed as active.
     /// </summary>
     /// <param name="hWnd">A handle to the window on the taskbar to be displayed as active.</param>
     void ActivateTab([In] IntPtr hWnd);

Alternative Managed API:

Do you know one? Please contribute it!

     /// <summary>
     /// Marks a taskbar item as active but does not visually activate it.
     /// </summary>
     /// <param name="hWnd">A handle to the window to be marked as active.</param>
     void SetActiveAlt([In] IntPtr hWnd);
}

Notes:

None.

[ComImport]
[Guid("56fdf344-fd6d-11d0-958a-006097c9a090")]
public class CoTaskbarList
{
}

VB Signature:

Declare Function ITaskbarList Lib "shell32.dll" (TODO) As TODO

Tips & Tricks:

Please add some!

Sample Code:

Please add some!

Documentation

VB.NET full Implementation:

Since I wanted this to work on x64 and x86 Plattforms I used the IntPtr based approach.

It works perfect using Windows7 (64) - in WinXP the Taskbar-Items tend to reappear after a while after hiding them.

Don't forget to Import System.Runtime.CompilerServices and System.Runtime.InteropServices

    <ComImport, TypeLibType(CShort(2)), Guid("56FDF344-FD6D-11D0-958A-006097C9A090"), ClassInterface(CShort(0))> _
    Public Class TaskbarListClass
    Implements ITaskbarList, TaskbarList
    ' Methods
    <MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
    Public Sub New()
    End Sub

    <MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
    Public Overridable Sub ActivateTab(<[In]> ByVal hwnd As IntPtr) Implements ITaskbarList.ActivateTab
    End Sub

    <MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
    Public Overridable Sub AddTab(<[In]> ByVal hwnd As IntPtr) Implements ITaskbarList.AddTab
    End Sub

    <MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
    Public Overridable Sub DeleteTab(<[In]> ByVal hwnd As IntPtr) Implements ITaskbarList.DeleteTab
    End Sub

    <MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
    Public Overridable Sub HrInit() Implements ITaskbarList.HrInit
    End Sub

    <MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
    Public Overridable Sub SetActivateAlt(<[In]> ByVal hwnd As IntPtr) Implements ITaskbarList.SetActivateAlt
        End Sub
    End Class

    <ComImport, Guid("56FDF342-FD6D-11D0-958A-006097C9A090"), CoClass(GetType(TaskbarListClass))> _
    Public Interface TaskbarList
    Inherits ITaskbarList
    End Interface

    <ComImport, InterfaceType(CShort(1)), Guid("56FDF342-FD6D-11D0-958A-006097C9A090")> _
    Public Interface ITaskbarList
    <MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
    Sub HrInit()
    <MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
    Sub AddTab(<[In]> ByVal hwnd As IntPtr)
    <MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
    Sub DeleteTab(<[In]> ByVal hwnd As IntPtr)
    <MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
    Sub ActivateTab(<[In]> ByVal hwnd As IntPtr)
    <MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
    Sub SetActivateAlt(<[In]> ByVal hwnd As IntPtr)
    End Interface

User-Defined Types:

None.

Alternative Managed API:

http://code.msdn.microsoft.com/WindowsAPICodePack

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

IntPtr windowHandle = ...;
var taskbarList = (ITaskbarList) new CoTaskbarList();
taskbarList.HrInit();
taskbarList.DeleteTab(windowHandle);

Documentation

http://msdn.microsoft.com/en-us/library/bb774652(VS.85).aspx

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions