Taskbar

Taskbar monitor and controller

Using this module you can monitor and control Windows Taskbar buttons.  Your script can get information about windows currently displayed in Taskbar as well as hide, delete or move its buttons.

Summary
TaskbarTaskbar monitor and controller
CountGet the number of buttons in the Taskbar.
DefineGet information about Taskbar buttons.
FlashFlash the Taskbar button.
FocusFocus the Taskbar.
DisableDisable the Taskbar.
GetHandleGet the Hwnd of the Taskbar.
GetRectGet Taskbar button placement.
HideHide Taskbar button.
MoveMove Taskbar button.
RemoveRemove Taskbar button.
Example
About

Count

Taskbar_Count()

Get the number of buttons in the Taskbar.

Returns

Number.  This includes hidden buttons.

Define

Taskbar_Define( Filter = "",
 pQ = "",
ByRef o1 = "~`a ",
ByRef o2 = "",
ByRef o3 = "",
ByRef o4 = "",
ByRef o5 = "",
ByRef o6 = "",
ByRef o7 = "")

Get information about Taskbar buttons.

Parameters

FilterContains process name, ahk_pid, ahk_id or 1-based position for which to return information.  If you specify position as Filter, you can use output variables to store information since only 1 item will be returned in that case.  If you omit this parameter, information about all buttons will be returned.
pQQuery parameter, by default “iwt”.
o1..o7Reference to output variables.

Query

hHandle.
iPosItion (1 based).
wParent Window handle.
pProcess Pid.
nProcess Name.
oIcOn handle.
tTitle of the parent window.

Returns

String containing icon information per line.

Flash

Taskbar_Flash(Hwnd = 0,
Options = "")

Flash the Taskbar button.

Parameters

HwndHwnd of the window to flash.
OptionsWhite space separated list of flash options.

Flash options

CaptionFlash caption.
ButtonFlash button.  This is default option.
AllFlash both.
TimerFlesh until next call of this function with empty Options argument.
TimerFGFlash continuously until the window comes to the foreground.
N.RDecimal number.  N specifies number of times to flash, by defult 3, R the flash rate (0 means cursor rate, default).

Returns

The return value specifies the window’s state before the call to the Flash function.  If the window caption was drawn as active before the call, the return value is nonzero.  Otherwise, the return value is zero.

Example

Taskbar_Flash( Taskbar_Define(2, "w"), "10.200 button")     ;flash first button 10 times with 200ms rate, only button

Focus

Taskbar_Focus()

Focus the Taskbar.

Remarks

After the Taskbar is focused, you can use {Space} or {Enter} to activate window or windows popup button to display system menu.

Disable

Taskbar_Disable(bDisable = true)

Disable the Taskbar.

Parameters

bDisableSet to FALSE to enable Taskbar.  By default TRUE.

GetHandle

Taskbar_GetHandle()

Get the Hwnd of the Taskbar.

Returns

Hwnd

GetRect

Taskbar_GetRect( Position,  
ByRef X = "",
ByRef Y = "",
ByRef W = "",
ByRef H = "")

Get Taskbar button placement.

Parameters

PositionPosition of the button.  Use negative position to retreive client coordinates.
X..HRefrence to output variables, optional.

Returns

String containing all outuput variables.

Remarks

This function can be used to determine invisible buttons.  Such buttons will have w & h equal to 0.

Hide

Taskbar_Hide(Handle,  
bHide = True)

Hide Taskbar button.

Parameters

PositionPosition of the button.
bHideSet to TRUE (default) to hide button.  FALSE will show it again.

Returns

TRUE if successful, or FALSE otherwise.

Move

Taskbar_Move(Pos,
NewPos)

Move Taskbar button.

Parameters

Pos1-based position of the button to be moved.
NewPos1-based postiion where the button will be moved.

Returns

TRUE indicates success.  FALSE indicates failure.

Remarks

When moving a button this function will also move its hidden button.

Remove

Taskbar_Remove(Position)

Remove Taskbar button.

Parameters

PositionPosition of the button.

Returns

TRUE indicates success.  FALSE indicates failure.

Example

Sort buttons on the Taskbar

;requires that there are no grouped buttons
SortTaskbar(type="R") {
    static WM_SETREDRAW=0xB
    h := Taskbar_GetHandle()
    SendMessage, WM_SETREDRAW, 0, , , ahk_id %h%
    loop, % Taskbar_Count() // 2
    {
        s := btns := Taskbar_Define("", "ti") "`n"
        Sort, s, %type%
        s := RegExReplace( s, "([^\n]*+\n){" A_Index-1 "}", "", "", 1 )
        s := SubStr(s, 1, InStr(S, "`n")-1)
        StringSplit, w, s, |

        Taskbar_Move( w2, 2 )
    }
    SendMessage, WM_SETREDRAW, 1, , , ahk_id %h%
}

About

Taskbar_Count()
Get the number of buttons in the Taskbar.
Taskbar_Define( Filter = "",
 pQ = "",
ByRef o1 = "~`a ",
ByRef o2 = "",
ByRef o3 = "",
ByRef o4 = "",
ByRef o5 = "",
ByRef o6 = "",
ByRef o7 = "")
Get information about Taskbar buttons.
Taskbar_Flash(Hwnd = 0,
Options = "")
Flash the Taskbar button.
Taskbar_Focus()
Focus the Taskbar.
Taskbar_Disable(bDisable = true)
Disable the Taskbar.
Taskbar_GetHandle()
Get the Hwnd of the Taskbar.
Taskbar_GetRect( Position,  
ByRef X = "",
ByRef Y = "",
ByRef W = "",
ByRef H = "")
Get Taskbar button placement.
Taskbar_Hide(Handle,  
bHide = True)
Hide Taskbar button.
Taskbar_Move(Pos,
NewPos)
Move Taskbar button.
Taskbar_Remove(Position)
Remove Taskbar button.
Close