Gui Progress Bar in Taskbar Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Gui Progress Bar in Taskbar

19 Apr 2024, 20:34

I have been using this v1 code to create a progress bar in the taskbar for a Gui.

I'm trying to convert it to work with v2, but I don't understand enough of the new commands yet.

Can someone help? I've looked at a few libraries on the forum & github, but it was too complex for me to understand and extract just this part that I need.

Code: Select all

SetTaskbarProgress(State := "", Value := "", Hwnd := "") {
    Static TBL := ""

    If (TBL = "") {
        TBL := ComObjCreate("{56FDF344-FD6D-11D0-958A-006097C9A090}", "{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}")
    }

    State := (State = "I" ? 1 : State = "N" ? 2 : State = "E" ? 4 : State = "P" ? 8 : 0)
    Hwnd := (Hwnd = "" ? WinExist() : Hwnd)
    DllCall(NumGet(NumGet(TBL + 0) + 10 * A_PtrSize), "Ptr", TBL, "Ptr", Hwnd, "UInt", State)

    If (Value != "") {
        DllCall(NumGet(NumGet(TBL + 0) + 9 * A_PtrSize), "Ptr", TBL, "Ptr", Hwnd, "Int64", Value, "Int64", 100)
    }

    return (TBL ? 0 : 1)
}
User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

Re: Gui Progress Bar in Taskbar  Topic is solved

19 Apr 2024, 21:44

I have no idea whether this is correct, but you can always give it a go.

Code: Select all

#Requires AutoHotkey v2.0
g := Gui(, 'Progress')
g.AddText 'w230', 'Test'
g.Show
SetTaskbarProgress('N', 35, g.Hwnd)
; SetTaskbarProgress('N', 65, g.Hwnd)

SetTaskbarProgress(State := '', Value := '', Hwnd := '') {
 Static p := ComObject('{56FDF344-FD6D-11D0-958A-006097C9A090}'
                     , '{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}').Ptr
 State := State = 'I' ? 1 : State = 'N' ? 2 : State = 'E' ? 4 : State = 'P' ? 8 : 0
 Hwnd  := Hwnd = '' ? WinExist() : Hwnd
 DllCall(NumGet(NumGet(p, 'UPtr') + 10 * A_PtrSize, 'UPtr'), 'Ptr', p, 'Ptr', Hwnd, 'UInt', State, 'Cdecl')
 If Value != ''
  DllCall(NumGet(NumGet(p, 'UPtr') + 9 * A_PtrSize, 'UPtr')
        , 'Ptr', p, 'Ptr', Hwnd, 'Int64', Value, 'Int64', 100, 'Cdecl')
 Return p ? False : True
}
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Gui Progress Bar in Taskbar

19 Apr 2024, 22:02

@mikeyww,

That is exactly what I needed. It works as expected. Thank you very much!
teadrinker
Posts: 4368
Joined: 29 Mar 2015, 09:41
Contact:

Re: Gui Progress Bar in Taskbar

20 Apr 2024, 09:38

This is more correct:

Code: Select all

#Requires AutoHotkey v2.0

wnd := Gui()
wnd.Show('w300 h100')
Sleep 1000

wnd.Title := 'TBPF_PAUSED'
Loop 3 {
    SetProgressOnTaskbarButton(wnd, TBPF_PAUSED := 8, 100)
    Sleep 500
    SetProgressOnTaskbarButton(wnd, TBPF_NOPROGRESS := 0)
    Sleep 500
}

wnd.Title := 'TBPF_INDETERMINATE'
SetProgressOnTaskbarButton(wnd, TBPF_INDETERMINATE := 1)
Sleep 4000

wnd.Title := 'TBPF_NORMAL'
Loop 500 {
    Sleep 10
    SetProgressOnTaskbarButton(wnd, TBPF_NORMAL := 2, A_Index, 500)
}

wnd.Title := 'TBPF_NOPROGRESS'
SetProgressOnTaskbarButton(wnd, TBPF_NOPROGRESS)
Sleep 1000
ExitApp

SetProgressOnTaskbarButton(wnd, state := 0, completed?, total := 100) {
/* 
    ITaskbarList3::SetProgressState https://goo.gl/JL8EyW
    state values: 
    TBPF_NOPROGRESS    := 0x0
    TBPF_INDETERMINATE := 0x1
    TBPF_NORMAL        := 0x2
    TBPF_ERROR         := 0x4
    TBPF_PAUSED        := 0x8
*/
    static CLSID_TaskbarList := '{56FDF344-FD6D-11d0-958A-006097C9A090}'
         , IID_ITaskbarList3 := '{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}'
         , ITaskbarList3 := ComObject(CLSID_TaskbarList, IID_ITaskbarList3)

    hWnd := IsObject(wnd) ? wnd.hwnd : wnd
    ComCall(SetProgressState := 10, ITaskbarList3, 'Ptr', hWnd, 'UInt', state)
    if IsSet(completed) {
        ComCall(SetProgressValue := 9, ITaskbarList3, 'Ptr', hWnd, 'Int64', completed, 'Int64', total)
    }
}

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: niCode, qltel, reddyshyam and 16 guests