Feels like wakin' up the dead but since I needed this feature and the topic was generously offered in the Help file, I dropped here and reviewed DerRaphael's code.
Changes are:
- replaced
InsertInteger with
NumPut
- fixed the
getTabName function
- adjusted
TCITEM struct size in all functions
- added button for the getTabName function testing
Hopefully I didn't break too much.

Enjoy!
Code:
; created by DerRaphael
; updated by Drugwash
MyImageList := IL_Create()
Loop 10
IL_Add(MyImageList, "shell32.dll", A_Index)
Gui, Add, Tab, x16 y216 w440 h20 0x38 -Wrap +Bottom gShoutActiveTab vMyIconTab
Gui +LastFound
SendMessage, 0x1303, 0, MyImageList, SysTabControl321 ; TCM_SETIMAGELIST
Gui, Tab
Gui, Add, Edit, y17 w440 h200 x16, This Edit Control is not part of the Tab Structure :)
Gui, Add, Button, y240 x16 w440 gTestRun, Start the Test
Gui, Add, Button, y+2 x16 w80 gTestGetName, Get name
AppendTab(1, "Berlin")
AppendTab(2, "London")
AppendTab(3, "New York")
AppendTab(4, "Helsinki")
AppendTab(5, "Bejing")
AppendTab(6, "Rom")
AppendTab(7, "Moskwa")
Gui, Show, x131 y91 h294 w477, Tabs with Icon Test
return
^l::
TestGetName:
Gui +LastFound
name := getTabName(GetActiveTab()-1)
MsgBox, Selected tab's name is %name%
return
TestRun:
MsgBox,1,Test #1, Press Enter to append a Tab with customized Label and Icon
IfMsgBox, OK
{
InputBox, TabName, Enter Name for new Tab, Please Name a TabName to Add
InputBox, IconNr, Enter IconNumber for new Tab, Please specify an Icon# from 1..10
AppendTab(IconNr, TabName)
}
MsgBox,1,Test #2, Press Enter to change Tab #1's Label and Icon
IfMsgBox, OK
{
InputBox, TabName, Enter Name for new Tab, Please Name a TabName to Add
InputBox, IconNr, Enter IconNumber for new Tab, Please specify an Icon# from 1..10
ModTab(IconNr, TabName, 0 )
}
MsgBox,1,Test #3, Press Enter to Remove Tab #2
IfMsgBox, OK
{
DelTab(1)
}
Msg=
Msg .= "There are " . CountTabs() . " Tabs in this SysTabControl`n"
Msg .= "Tab #" . GetActiveTab() . " is the active Tab`n"
Msg .= "Tab #" . GetTabFocus() . " is the focused Tab`n"
MsgBox,,Status, %Msg%
return
ShoutActiveTab:
GuiControlGet, label,, MyIconTab
GuiControl,,Edit1, The Selected Tab is labeled with "%label%"
return
AppendTab(IconNumber, TabName) ; TCM_INSERTITEM
{
VarSetCapacity(TCITEM, 28, 0)
NumPut(3, TCITEM, 0, "UInt")
NumPut(&TabName, TCITEM, 12, "UInt")
NumPut(IconNumber - 1, TCITEM, 20, "UInt")
SendMessage, 0x1307, 999, &TCITEM, SysTabControl321
}
ModTab(IconNumber, TabName, Index) ; TCM_SETITEM
{
VarSetCapacity(TCITEM, 28, 0)
NumPut(3, TCITEM, 0, "UInt")
NumPut(&TabName, TCITEM, 12, "UInt")
NumPut(IconNumber - 1, TCITEM, 20, "UInt")
SendMessage, 0x1306, Index, &TCITEM, SysTabControl321
}
DelTab(Index) ; TCM_DELETEITEM
{
SendMessage, 0x1308, Index, 0, SysTabControl321
}
CountTabs() ; TCM_GETITEMCOUNT
{
SendMessage, 0x1304, 0, 0, SysTabControl321
Return, %ErrorLevel%
}
GetActiveTab() ;
{
ControlGet, ActiveTab, Tab,, SysTabControl321
Return, % ActiveTab
}
GetTabFocus() ; TCM_GETCURFOCUS
{
SendMessage, 0x132F, 0, 0, SysTabControl321
Return, % ErrorLevel += 1
}
getTabName(item) ; TCM_GETITEM
{
szBuf=254
VarSetCapacity(TCITEM, 28, 0)
VarSetCapacity(Buffer, szBuf, 0)
NumPut(1, TCITEM, 0, "UInt")
NumPut(&Buffer, TCITEM, 12, "UInt")
NumPut(szBuf, TCITEM, 16, "Int")
SendMessage, 0x1305, item, &TCITEM, SysTabControl321
Loop, %szBuf%
{
getchr := NumGet(Buffer, A_Index - 1, "UChar")
if !getchr
break
newbuf := newbuf . Chr(getchr)
}
return newbuf
}
GuiClose:
IL_Destroy(MyImageList) ; Required for image lists used by tab controls.
ExitApp