How to view progress in Taskbar

Asked

Viewed 126 times

1

Hello guys I recently saw on a forum that is yes possible to show progress in Taskbar (compatible with Windows 7)

I have the following code:

using System;
using System.Runtime.InteropServices;

namespace System.Windows.Forms.TaskBar {
    /// <summary>
    /// Represents the thumbnail progress bar state.
    /// </summary>
    public enum ThumbnailProgressState {
        /// <summary>
        /// No progress is displayed.
        /// </summary>
        NoProgress = 0,
        /// <summary>
        /// The progress is indeterminate (marquee).
        /// </summary>
        Indeterminate = 0x1,
        /// <summary>
        /// Normal progress is displayed.
        /// </summary>
        Normal = 0x2,
        /// <summary>
        /// An error occurred (red).
        /// </summary>
        Error = 0x4,
        /// <summary>
        /// The operation is paused (yellow).
        /// </summary>
        Paused = 0x8
    }

    [ComImportAttribute()]
    [GuidAttribute("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")]
    [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
    internal interface ITaskbarList3 {
        // ITaskbarList
        [PreserveSig]
        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
        void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal);
        void SetProgressState(IntPtr hwnd, ThumbnailProgressState tbpFlags);
    }

    [GuidAttribute("56FDF344-FD6D-11d0-958A-006097C9A090")]
    [ClassInterfaceAttribute(ClassInterfaceType.None)]
    [ComImportAttribute()]
    internal class CTaskbarList {}
}

How can I use it?

  • What do you mean by "show a progress bar on Taskbar"? You want to create a progress barar in a windows application?

  • 1

    I believe he’s talking about using the application icon in the Windows taskbar, which is large and transparent, as a progress bar. How a file transfer window (download or copy) does.

1 answer

2


I found the solution to this code:

void Form_Load(object sender, EventArgs e) {
    var taskbar = ((ITaskBarList3) CTaskBarList);
    taskbar.HrInit();
    taskbar.SetProgressState(ThumbnailProgessState.Normal);
    taskbar.SetProgressValue(this.Handle, 50, 0); //Handle é do Form
}

And so progress will be shown in Taskbar. Compatible with Windows 7 and 8:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.