Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Icons in tabs

  • Please log in to reply
18 replies to this topic
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
I've been going over the documentation and it seems I can't add an icon to a tab and have the tab's text label align to the left beside it, like the windows taskbar and in many apps. I find if I add an icon with gui, add, picture - the icon disappears as soon as I change tab.

I'd like a more formal way to "assign" icons to tabs like so:

Gui, Tab, 1
Gui, Add, Icon, some.ico, 1 
Gui, Add, Radio, -tabstop g1/16 x10 y70 w50 h20, 1/16
Gui, Add, Radio, -tabstop g1/8 x60 y70 w50 h20, 1/8
Gui, Add, Radio, -tabstop g1/4 x110 y70 w50 h20, 1/4
Gui, Add, Radio, -tabstop g1/2 x160 y70 w50 h20, 1/2
; etc

"Anything worth doing is worth doing slowly." - Mae West
Posted Image

  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Thanks for the idea. Until the feature gets built in, here's a working demonstration script. It puts icons in a tab control via SendMessage. Known limitation: it won't work if you ever put a custom background color in effect for the window without also using the BackgroundDefault option for the tab control.
MyImageList := IL_Create()
Loop 3  ; Load the ImageList with a series of icons from the DLL.
	IL_Add(MyImageList, "shell32.dll", A_Index)  ; Omits DLL path so that it works on Windows 9x too.

Gui, Add, Tab, vMyTab
Gui +LastFound
SendMessage, 0x1303, 0, MyImageList, SysTabControl321   ; 0x1303 is TCM_SETIMAGELIST.

AddTab(1, "First")  ; First parameter = icon number; second = tab name.
AddTab(2, "Second")
AddTab(3, "Third")

Gui, Tab, 1
Gui, Add, Text,, Test Text
Gui, Tab, 2
Gui, Add, Button,, Test Button
Gui, Tab, 3
Gui, Add, Edit,, Test Edit

Gui, Show

AddTab(IconNumber, TabName)  ; Relies on caller having set the last found window for us.
	VarSetCapacity(TCITEM, 100, 0)
	InsertInteger(3, TCITEM, 0)  ; Mask (3) comes from TCIF_TEXT(1) + TCIF_IMAGE(2).
	InsertInteger(&TabName, TCITEM, 12)  ; pszText
	InsertInteger(IconNumber - 1, TCITEM, 20)  ; iImage: -1 to convert to zero-based.
	SendMessage, 0x1307, 999, &TCITEM, SysTabControl321  ; 0x1307 is TCM_INSERTITEM

InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
	Loop %pSize%  ; Copy each byte in the integer into the structure as raw binary data.
		DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)

IL_Destroy(MyImageList)  ; Required for image lists used by tab controls.
Edit: Streamlined the code a little bit.