 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Serenity
Joined: 08 Nov 2004 Posts: 1272
|
Posted: Fri Oct 28, 2005 5:28 pm Post subject: Icons in tabs |
|
|
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:
| Code: | 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
 |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10667
|
Posted: Sat Oct 29, 2005 3:52 am Post subject: |
|
|
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.
| Code: | 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
return
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)
}
GuiClose:
IL_Destroy(MyImageList) ; Required for image lists used by tab controls.
ExitApp |
Edit: Streamlined the code a little bit.
Last edited by Chris on Wed Sep 20, 2006 1:11 pm; edited 3 times in total |
|
| Back to top |
|
 |
kapege.de
Joined: 07 Feb 2005 Posts: 192 Location: Munich, Germany
|
Posted: Sat Oct 29, 2005 11:36 am Post subject: |
|
|
Chris, that's awesome!
The DLL-calls looks very similar to those you have to use putting icons into the status bar. I try to to get your act together but I failed again.
Could you help me with that status bar a last time, so it is complete?
Then we have: simple bar, multiple bar and graphic elements in bar - the whole story.
That would be great!
Many thanks for your Help! _________________ Peter
Wisenheiming for beginners: KaPeGe (German only, sorry) |
|
| Back to top |
|
 |
Serenity
Joined: 08 Nov 2004 Posts: 1272
|
Posted: Sat Oct 29, 2005 2:43 pm Post subject: |
|
|
Thanks Chris! I had no idea DllCall could be used this way. _________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10667
|
Posted: Sun Oct 30, 2005 1:17 pm Post subject: |
|
|
| kapege.de wrote: | | putting icons into the status bar. |
The following seems to work:
| Code: | hicon := DllCall("LoadImage", UInt, NULL, Str, "icon_main.ico", UInt, 1, Int, 16, Int, 16, UInt, 0x10|0x2000)
if hicon
SendMessage, 0x40F, 0, hicon,, ahk_id %BarHWND% ; 0x40F is SB_SETICON |
|
|
| Back to top |
|
 |
Serenity
Joined: 08 Nov 2004 Posts: 1272
|
Posted: Fri Nov 04, 2005 4:33 pm Post subject: |
|
|
Hi Chris, the example you posted didn't show icons until I changed line 30 to:
| Code: | | VarSetCapacity(TCITEM, 100) |
_________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10667
|
Posted: Sat Nov 05, 2005 8:05 am Post subject: |
|
|
| You mean the only difference is you omitted the zero as the third parameter? If so, it goes against all logic and I can't think of any explanation. |
|
| Back to top |
|
 |
Serenity
Joined: 08 Nov 2004 Posts: 1272
|
Posted: Sat Nov 05, 2005 1:32 pm Post subject: |
|
|
That's really strange. What I copied from the board was actually written as:
| Code: | | VarSetCapacity(0, TCITEM, 100) |
_________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10667
|
Posted: Sat Nov 05, 2005 4:05 pm Post subject: |
|
|
| Thanks for the follow-up. I don't recall having edited that post in that way, but maybe I did. |
|
| Back to top |
|
 |
kapege.de
Joined: 07 Feb 2005 Posts: 192 Location: Munich, Germany
|
Posted: Tue Nov 08, 2005 2:05 am Post subject: |
|
|
At last we've a complete set of commands to control the status bar!
The following may be saved as a own file and included with a #Include
| Code: | ; SB_Segments(segs) initiates a Status Bar and divides it into segments. Depends on "VarSetCapacity" and "InsertInteger".
; Usage: You put the positions of your segments into a string like this "10,20,100,200,-1". The numbers determins the right edge of the segment, "-1" means 'make a final segment filling the remaining space until the rightmost border'
; Sample: SB_Segments("20,44,200,350,450,-1")
; To get the correct GUI for a status bar you should have to do a 'Gui +LastFound' before calling 'SB_Segments'
SB_Segments(segs)
{
global BarHWND
; WS_CHILD (0x40000000) + WS_VISIBLE (0x10000000) = 0x50000000:
BarHWND := DllCall("CreateStatusWindow", int, 0x50000000, str, "", UInt, WinExist(), UInt, 5555)
n = 0
loop, Parse, segs, CSV ; How many segments are needed -> n
n++
VarSetCapacity( parts, 4*n ) ; Create 'parts' and make it 4 Byte times n segments large
loop, Parse, segs, CSV ; Fill the var 'parts' with content (the postitons)
InsertInteger( A_LoopField, parts, 4 * ( A_Index - 1 ) ) ; Reserves 4 Bytes per run in the string "parts"
SendMessage, 0x404, %n%, &parts,, ahk_id %BarHWND% ; Sends the number of segments and its positions to the status bar
return, BarHWND
}
; SB_Icon(seg, name) adds an icon to a specific segment within a status bar
; SEG is the number of the segment (the first segment is 1, the second 2...)
; NAME is the filename of the graphic to show
; Sample: SB_Icon(1, "icon.ico") This puts the file 'icon.ico' into the first segment of your status bar
SB_Icon(seg, name)
{
global BarHWND
seg-- ; subs 1 from the segment, because it starts with zero
hicon := DllCall("LoadImage", UInt, NULL, Str, name, UInt, 1, Int, 16, Int, 16, UInt, 0x10|0x2000)
if hicon
SendMessage, 0x40F, seg, hicon,, ahk_id %BarHWND% ; 0x40F is SB_SETICON
return
}
; SB_Text(seg, text) puts a text into a segment of your status bar
; SEG is the number of the segment (the first segment is 1, the second 2...)
; TEXT is the text to display. Put it into doublequotes
; Sample: SB_Text(1,"Hello World!")
SB_Text(seg, text)
{
global BarHWND
seg--
t2 = %text%
SendMessage, 0x401, %seg%, &t2,, ahk_id %BarHWND% ; 0x401 is SB_SETTEXT
return
}
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
; To preserve any existing contents in pDest, only pSize number of bytes starting at pOffset
; are altered in it. The caller must ensure that pDest has sufficient capacity.
{
mask := 0xFF ; This serves to isolate each byte, one by one.
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 & mask) >> 8 * (A_Index - 1))
mask := mask << 8 ; Set it up for isolation of the next byte.
}
}
|
Additionally you may put a line like this into your script to create space for the status bar:
| Code: | Gui, Add, Text, Hidden, xxxxxxx ; Reserves space for bar; for use with "Gui Show".
|
That's my contribution to the community.
@Chris: You gave me such a powerful proggy. Thank you a 1000 times!
P.S.: If it's worth you may put that into your script collection. _________________ Peter
Wisenheiming for beginners: KaPeGe (German only, sorry) |
|
| Back to top |
|
 |
lingoist
Joined: 05 Oct 2004 Posts: 121 Location: Brasília, Brazil
|
Posted: Wed Mar 21, 2007 10:44 am Post subject: |
|
|
I'd like to add an icon after a tab is created, because icons disappear when I use GuiControl.
Would it be possible?
ACTUAL CODE
| Code: |
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
GuiControl, , MyControlTab, |First|Second||Third
|
"WISH CODE"
| Code: |
Gui, Tab, First
Gui, Add, Text,, Test Text
Gui, Tab, Second
Gui, Add, Button,, Test Button
Gui, Tab, Third
Gui, Add, Edit,, Test Edit
GuiControl, , MyControlTab, |First|Second||Third
AddIconToTab(1, "First") ; First parameter = icon number; second = tab name (NUMBER WOULD ALSO BE OK FOR ME).
AddIconToTab(2, "Second")
AddIconToTab(3, "Third")
|
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10667
|
Posted: Wed Mar 21, 2007 2:12 pm Post subject: |
|
|
| It can probably be done via the TCM_SETITEM Message. Maybe you or someone else wouldn't mind doing the research and sharing your results. |
|
| Back to top |
|
 |
nesfred Guest
|
Posted: Wed Apr 25, 2007 4:19 pm Post subject: How to use customized icons with this? |
|
|
Hello,
How can I change the icons displayed in the tabs?
I would like to use my own customized icons, but I don't see any reference to them... are they included in the dll?
Thanks a lot for your help! |
|
| Back to top |
|
 |
DerRaphael Guest
|
Posted: Fri Nov 23, 2007 10:14 am Post subject: Some Test Cases for Icons in Tabs |
|
|
After i read about the possibility to add Icons to a Tab List, i played around
and generated some test cases for playing around with Icons, Renaming iconified Tabs, deleting 'em adding some more and backreferencing 'em
here's the code:
| Code: |
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, y250 x16 w440 gTestRun, Start the Test
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::
getTabName(1)
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, 100, 0)
InsertInteger(3, TCITEM, 0)
InsertInteger(&TabName, TCITEM, 12)
InsertInteger(IconNumber - 1, TCITEM, 20)
SendMessage, 0x1307, 999, &TCITEM, SysTabControl321
}
ModTab(IconNumber, TabName, Index) ; TCM_SETITEM
{
VarSetCapacity(TCITEM, 100, 0)
InsertInteger(3, TCITEM, 0)
InsertInteger(&TabName, TCITEM, 12)
InsertInteger(IconNumber - 1, TCITEM, 20)
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
{
VarSetCapacity(TCITEM, 512, 0)
InsertInteger(3, TCITEM, 0)
SendMessage, 0x1305, item, &TCITEM, SysTabControl321
MsgBox %ErrorLevel%
}
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
{
Loop %pSize%
DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
}
GuiClose:
IL_Destroy(MyImageList) ; Required for image lists used by tab controls.
ExitApp
|
There is still a Message, with which its possible to get the Icon Number associated with a Tab. Its the Message TCM_GETITEM which i didnt master. The Returncode is FAIL when i give it a call.
I guess the TCITEM is somehow corrupted, but i dont get it how to set it up correctly.
http://msdn2.microsoft.com/en-us/library/bb760589.aspx for TCM_GETITEM
http://msdn2.microsoft.com/en-us/library/bb760554.aspx for TCITEM
Well Then so far ... happy playing around
Keep Scriptin'
DerRaphael |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4473 Location: Qld, Australia
|
Posted: Fri Nov 23, 2007 12:59 pm Post subject: |
|
|
Try replacing | Code: | | InsertInteger(3, TCITEM, 0) | with | Code: | | InsertInteger(2, TCITEM, 0) | 3 is a combination of TCIF_IMAGE (2) and TCIF_TEXT (1). | TCM_GETITEM wrote: | If the mask member specifies the TCIF_TEXT value, the pszText member must contain the address of the buffer that receives the item text, and the cchTextMax member must specify the size of the buffer.
| I also recommend reading up on NumPut, which was added as a built-in function in AutoHotkey v.1.0.47, and is a more efficient alternative to InsertInteger.
| nesfred wrote: | | I would like to use my own customized icons, but I don't see any reference to them... are they included in the dll? | I know this was posted months ago, but for anyone that is wondering the same thing:
Each Tab has an associated image index, which is an index into the Tab Control's Image List. So the IconNumber parameter of AddTab corresponds to the return values of IL_Add(), which is what adds the individual images to the Image List. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|