Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Windows 7] SetTaskbarProgress


  • Please log in to reply
17 replies to this topic
Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
SetTaskbarProgress(pct[, state, hwnd])
Accesses Windows 7's ability to display a progress bar behind a taskbar button.

; SetTaskbarProgress  -  Requires Windows 7.
;
; pct    -  A number between 0 and 100 or a state value (see below).
; state  -  "N" (normal), "P" (paused), "E" (error) or "I" (indeterminate).
;           If omitted (and pct is a number), the state is not changed.
; hwnd   -  The ID of the window which owns the taskbar button.
;           If omitted, the Last Found Window is used.
;
SetTaskbarProgress(pct, state="", hwnd="")
{
    static tbl, s0:=0, sI:=1, sN:=2, sE:=4, sP:=8
    if !tbl
    {
        COM_Init() ; Create a TaskbarList object with ITaskbarList3 interface:
        if DllCall("ole32\CoCreateInstance", "uint", COM_GUID4String(CLSID,"{56FDF344-FD6D-11d0-958A-006097C9A090}"), "uint", 0, "uint", 21, "uint", COM_GUID4String(IID,"{ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf}"), "uint*", tbl) != 0
        {
            MsgBox 16,, Error creating TaskbarList object. Is this script running on Windows 7? Exiting.
            ExitApp
        }
    }
    if hwnd =
        hwnd := WinExist()
    if pct is not number
        state := pct, pct := ""
    else if (pct = 0 && state="")
        state := 0, pct := ""
    if state in 0,I,N,E,P   ; ITaskbarList3::SetProgressState
        DllCall(NumGet(NumGet(tbl+0)+40), "uint", tbl, "uint", hwnd, "uint", s%state%)
    if pct !=               ; ITaskbarList3::SetProgressValue
        DllCall(NumGet(NumGet(tbl+0)+36), "uint", tbl, "uint", hwnd, "int64", pct*10, "int64", 1000)
}

Example:
Gui, Font, s15
Gui, Add, Text,, % "This GUI should show a progress bar on its taskbar button.`n"
                 . "It will demonstrate the four different progress states:`n"
                 . "(N)ormal, (P)aused, (E)rror and (I)ndeterminate."
Gui, Show        ; Show the window and taskbar button.
Gui, +LastFound  ; SetTaskbarProgress will use this window.
Loop
{
    progress_states=NPE
    Loop, Parse, progress_states
    {
        SetTaskbarProgress(0, A_LoopField)
        Loop 50 {
            SetTaskbarProgress(A_Index*2)
            Sleep 50
        }
        Sleep 1000
        Loop 50 {
            SetTaskbarProgress(100-A_Index*2)
            Sleep 50
        }
        SetTaskbarProgress(0)
        Sleep 1000
    }
    SetTaskbarProgress("I")
    Sleep 4000
}
GuiClose:
GuiEscape:
ExitApp


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Damn, I'm not on 7 yet, assume it looks very nice :D

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007
It works flawlessly here :D

ashimoi
  • Guests
  • Last active:
  • Joined: --
:p I like it,it is what i need!

BoffinbraiN
  • Members
  • 114 posts
  • Last active: Jun 18 2013 07:03 PM
  • Joined: 16 Nov 2009
I'm trying to use this with Windows 7 evaluation version and I get errors saying these COM functions don't exist, namely COM_Init and COM_GUID4String.

entropic
  • Members
  • 181 posts
  • Last active: Nov 27 2011 03:15 AM
  • Joined: 21 Dec 2008
You likely need the COM Standard Library by Sean

BoffinbraiN
  • Members
  • 114 posts
  • Last active: Jun 18 2013 07:03 PM
  • Joined: 16 Nov 2009
Thanks for that! I'm not experienced with Library stuff so I would never have guessed how to fix it.

Now I want to find out how to do these neat things in Java. :)

RIST
  • Members
  • 39 posts
  • Last active: Aug 17 2012 08:36 PM
  • Joined: 08 May 2008

You likely need the COM Standard Library by Sean


i have that but error is not gone :/
Keegi Siin ka Eestlane? :)

Codybear - Not Logged in
  • Guests
  • Last active:
  • Joined: --
Error is at line 12:

011:(
012: SetTaskbarProgress(0, A_LoopField)
013:Loop,50
013:{
014:SetTaskbarProgress(A_Index*2)
015:Sleep,50
016:}

I have the COM Library, Win7 Pro edition.
Not sure why it's not working...


For the time being I have a program called WinFox, it integrates Firefox into the win7 taskbar like the file explorer is.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

Error is at line 12:

What error? Did you copy the SetTaskbarProgress function into your script (or save it as SetTaskbarProgress.ahk in a Lib folder)?

GDur
  • Members
  • 82 posts
  • Last active: Feb 05 2012 09:08 PM
  • Joined: 15 Nov 2009
can u make a script, wich makes me able to create those buttons for my own programms?
:shock:
Posted Image

that would be awesome!
*can't live without AHK*

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
I suppose it can be done using the ThumbBarAddButtons method of the ITaskbarList3 (tbl) interface which this script uses. I don't plan on doing it.

GDur
  • Members
  • 82 posts
  • Last active: Feb 05 2012 09:08 PM
  • Joined: 15 Nov 2009
ok
thx :(
*can't live without AHK*

GreenHouse
  • Guests
  • Last active:
  • Joined: --
Hi :D
i think i doesnt work on UNICODE 64bit and ANSI 32bit; just on UNICODE 32 bit, does it?

FrostByte
  • Members
  • 148 posts
  • Last active: Sep 16 2015 05:56 PM
  • Joined: 08 Nov 2012

No, it only works with ANSI 32-bit.


FrostByte and the Artemis Asylrum® Corporation
View my projects: Artemis Media Player

FrostByte62.com is down. I'll find another place to host my stuff soon...after I get done procrastinating some more. :)