App's Taskbar as ProgressBar

OSVBNET 1,386 Reputation points
2022-04-15T21:56:26.357+00:00

Hello,
Never found a code snippet for VB.NET (fw4.0) to show my .net app taskbar as ProgressBar!
Anyone have any, please? :(
Thanks.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,632 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 82,406 Reputation points
    2022-04-19T08:29:38.557+00:00

    A basic test with P/Invoke :

    194188-itaskbarlist3.gif

    (remove space at .S leep...)

        pTaskbarList = CType((New TaskbarList()), ITaskbarList3)  
        Dim nMaxValue As Integer = 100  
        If (pTaskbarList IsNot Nothing) Then  
            Dim hr As HRESULT = pTaskbarList.HrInit()  
            hr = pTaskbarList.SetProgressState(Me.Handle, TBPFLAG.TBPF_INDETERMINATE)  
            For i As Integer = 0 To nMaxValue - 1  
                pTaskbarList.SetProgressValue(Me.Handle, i, nMaxValue)  
                System.Threading.Thread.S leep(10)  
            Next  
            pTaskbarList.SetProgressState(Me.Handle, TBPFLAG.TBPF_NOPROGRESS)  
        End If  
    

    Declarations :

    Public Enum HRESULT As Integer  
        S_OK = 0  
        S_FALSE = 1  
        E_NOINTERFACE = &H80004002  
        E_NOTIMPL = &H80004001  
        E_FAIL = &H80004005  
        E_UNEXPECTED = &H8000FFFF  
        E_OUTOFMEMORY = &H8007000E  
    End Enum  
    
    <StructLayout(LayoutKind.Sequential)>  
    Public Structure RECT  
        Public left As Integer  
        Public top As Integer  
        Public right As Integer  
        Public bottom As Integer  
        Public Sub New(left As Integer, top As Integer, right As Integer, bottom As Integer)  
            Me.left = left  
            Me.top = top  
            Me.right = right  
            Me.bottom = bottom  
        End Sub  
    End Structure  
    
    <ComImport>  
    <Guid("56FDF342-FD6D-11d0-958A-006097C9A090")>  
    <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>  
    Interface ITaskbarList  
        Function HrInit() As HRESULT  
        Function AddTab(hwnd As IntPtr) As HRESULT  
        Function DeleteTab(hwnd As IntPtr) As HRESULT  
        Function ActivateTab(hwnd As IntPtr) As HRESULT  
        Function SetActiveAlt(hwnd As IntPtr) As HRESULT  
    End Interface  
    
    <ComImport>  
    <Guid("602D4995-B13A-429b-A66E-1935E44F4317")>  
    <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>  
    Interface ITaskbarList2  
        Inherits ITaskbarList  
        Overloads Function HrInit() As HRESULT  
        Overloads Function AddTab(hwnd As IntPtr) As HRESULT  
        Overloads Function DeleteTab(hwnd As IntPtr) As HRESULT  
        Overloads Function ActivateTab(hwnd As IntPtr) As HRESULT  
        Overloads Function SetActiveAlt(hwnd As IntPtr) As HRESULT  
        Function MarkFullscreenWindow(hwnd As IntPtr, fFullscreen As Boolean) As HRESULT  
    End Interface  
    
    <ComImport>  
    <Guid("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")>  
    <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>  
    Interface ITaskbarList3  
        Inherits ITaskbarList2  
        Overloads Function HrInit() As HRESULT  
        Overloads Function AddTab(hwnd As IntPtr) As HRESULT  
        Overloads Function DeleteTab(hwnd As IntPtr) As HRESULT  
        Overloads Function ActivateTab(hwnd As IntPtr) As HRESULT  
        Overloads Function SetActiveAlt(hwnd As IntPtr) As HRESULT  
        Overloads Function MarkFullscreenWindow(hwnd As IntPtr, fFullscreen As Boolean) As HRESULT  
        Function SetProgressValue(hwnd As IntPtr, ullCompleted As UInt64, ullTotal As UInt64) As HRESULT  
        Function SetProgressState(hwnd As IntPtr, tbpFlags As TBPFLAG) As HRESULT  
        Function RegisterTab(hwndTab As IntPtr, hwndMDI As IntPtr) As HRESULT  
        Function UnregisterTab(hwndTab As IntPtr) As HRESULT  
        Function SetTabOrder(hwndTab As IntPtr, hwndInsertBefore As IntPtr) As HRESULT  
        Function SetTabActive(hwndTab As IntPtr, hwndMDI As IntPtr, dwReserved As UInteger) As HRESULT  
        Function ThumbBarAddButtons(hwnd As IntPtr, cButtons As UInteger, ByRef pButton As THUMBBUTTON) As HRESULT  
        Function ThumbBarUpdateButtons(hwnd As IntPtr, cButtons As UInteger, ByRef pButton As THUMBBUTTON) As HRESULT  
        Function ThumbBarSetImageList(hwnd As IntPtr, himl As IntPtr) As HRESULT  
        Function SetOverlayIcon(hwnd As IntPtr, hIcon As IntPtr, pszDescription As String) As HRESULT  
        Function SetThumbnailTooltip(hwnd As IntPtr, pszTip As String) As HRESULT  
        Function SetThumbnailClip(hwnd As IntPtr, ByRef prcClip As RECT) As HRESULT  
    End Interface  
    
    Public Enum TBPFLAG  
        TBPF_NOPROGRESS = 0  
        TBPF_INDETERMINATE = &H1  
        TBPF_NORMAL = &H2  
        TBPF_ERROR = &H4  
        TBPF_PAUSED = &H8  
    End Enum  
    
    Public Enum THUMBBUTTONMASK  
        THB_BITMAP = &H1  
        THB_ICON = &H2  
        THB_TOOLTIP = &H4  
        THB_FLAGS = &H8  
    End Enum  
    
    Public Enum THUMBBUTTONFLAGS  
        THBF_ENABLED = 0  
        THBF_DISABLED = &H1  
        THBF_DISMISSONCLICK = &H2  
        THBF_NOBACKGROUND = &H4  
        THBF_HIDDEN = &H8  
        THBF_NONINTERACTIVE = &H10  
    End Enum  
    
    <StructLayout(LayoutKind.Sequential)>  
    Public Structure THUMBBUTTON  
        Public dwMask As THUMBBUTTONMASK  
        Public iId As UInteger  
        Public iBitmap As UInteger  
        Public hIcon As IntPtr  
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)>  
        Public szTip As String  
        Public dwFlags As THUMBBUTTONFLAGS  
    End Structure  
    
    <ComImport, Guid("56FDF344-FD6D-11d0-958A-006097C9A090")>  
    Public Class TaskbarList  
    End Class  
    
    
    Dim pTaskbarList As ITaskbarList3 = Nothing  
    

1 additional answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 27,666 Reputation points Microsoft Vendor
    2022-04-18T05:57:25.513+00:00

    Hi @OSVBNET ,
    Here's a link to a c# solution which you can refer to.
    It may take some time to convert the C# code to VB code, but you can also find some conversion tools.
    https://stackoverflow.com/q/1295890/17334287
    Best Regards.
    Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.