Large Icons in Tab Control Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jballi
Posts: 571
Joined: 29 Sep 2013, 17:34

Large Icons in Tab Control

31 Mar 2018, 19:12

I'm trying to add large icons to a tab control.

Tab2: With an added Redraw command when a new icon is set, the Tab2 control appears to work correctly. The icons display correctly and the control correctly recognizes the icon and adjusts the size of the tab accordingly. GUI controls added after the image list is attached are added in the correct location.

Tab3: The Tab3 control is another situation entirely. Everything appears to work but the bottom section of the tabs are not drawn correctly. On my computer, the bottom half is covered in what appears to be the top of the tab workspace area. This is what it looks like on my computer.

Image

Adding a Redraw command here and there appears to help a little but often the GUI controls within the tabs are hidden.

The following is the script I used to duplicate the problem.

Code: Select all

#NoEnv
#SingleInstance Force
ListLines Off

TabLocation:="top"
    ;-- Change to "left", "right", or "bottom" if desired.

gui -DPIScale -MinimizeBox
Loop 2
    {
    if (A_Index=1)
        {
        gui Font,Bold
        gui Add,Text,xm,Tab2 Control
        gui Font
        gui Add,Tab2,xm w350 h200 hWndhTab2 %TabLocation% cDefault,First|Second|Third
        }
     else
        {
        gui Font,Bold
        gui Add,Text,ym Section,Tab3 Control
        gui Font
        gui Add,Tab3,xs w350 h200 hWndhTab3 %TabLocation% cDefault,First|Second|Third
        }

    gosub SetImageList

    gui Tab,First
    gui Add,Text,,Tab control with tabs on the %TabLocation%.
    gui Tab,Second
    gui Add,Button,,Button
    gui Tab,Third
    gui Add,Edit,,Edit control
    gui Tab
    }

gui Add,Button,xm w150 gSetIcons,Set Tab Icons
gui Add,Button,xm y+1 wp gRedraw,Redraw
gui Add,Button,xm gReload,%A_Space% Reload... %A_Space%
gui Show
;;;;;WinSet Redraw,,ahk_id %hTab3%
return


GUIEscape:
GUIClose:
IL_Destroy(hIL)
ExitApp


Redraw:
WinSet Redraw,,ahk_id %hTab2%
WinSet Redraw,,ahk_id %hTab3%
return


Reload:
Reload
return


SetIcons:
ListOfIconIndexes:=""
Loop 3
    {
    Loop
        {
        Random IconIndex,1,150
        if IconIndex not in %ListOfIconIndexes%
            Break
        }

    ListOfIconIndexes.=(StrLen(ListOfIconIndexes) ? ",":"") . IconIndex
    TAB_SetIcon(hTab2,A_Index,IconIndex)
    TAB_SetIcon(hTab3,A_Index,IconIndex)
    }

return


SetImageList:
hIL:=IL_Create(150,,True)
Loop 150
    IL_Add(hIL,"shell32.dll",A_Index)

TAB_SetImageList(hTab2,hIL)
TAB_SetImageList(hTab3,hIL)
gosub SetIcons
return


;*******************
;*                 *
;*    Functions    *
;*                 *
;*******************
TAB_SetIcon(hTab,iTab,iIL)
    {
    Static Dummy18408860

          ;-- Mask
          ,TCIF_TEXT      :=0x1
          ,TCIF_IMAGE     :=0x2
          ,TCIF_PARAM     :=0x8
          ,TCIF_RTLREADING:=0x4
          ,TCIF_STATE     :=0x10

          ;-- Messages
          ,TCM_SETITEMA:=0x1306  ;-- TCM_FIRST + 6
          ,TCM_SETITEMW:=0x133D  ;-- TCM_FIRST + 61

    VarSetCapacity(TCITEM,A_PtrSize=8 ? 40:28,0)
    NumPut(TCIF_IMAGE,TCITEM,0,"UInt")                  ;-- mask
    NumPut(iIL-1,TCITEM,A_PtrSize=8 ? 28:20,"Ptr")      ;-- iImage
    SendMessage A_IsUnicode ? TCM_SETITEMW:TCM_SETITEMA,iTab-1,&TCITEM,,ahk_id %hTab%
    WinSet Redraw,,ahk_id %hTab%
        ;-- Programming note:  This is required because without, a trace of the
        ;   previous icon is occasionally left behind when the new icon is
        ;   drawn.
    }

TAB_SetImageList(hTab,hIL)
    {
    Static TCM_SETIMAGELIST:=0x1303  ;-- TCM_FIRST + 3
    SendMessage TCM_SETIMAGELIST,0,hIL,,ahk_id %hTab%
    Return ErrorLevel  ;-- Handle of previous IL or 0 if this was no previous IL
    }
Any help would be appreciated.
lexikos
Posts: 6609
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Large Icons in Tab Control  Topic is solved

31 Mar 2018, 23:20

Windows isn't great at handling overlap between controls, hence the inconsistency between drawing and redrawing.

There is overlap because:
Tab3: [...] Controls are placed within an invisible "tab dialog" which moves and resizes with the tab control.
Source: GUI Control Types
The key here is that the tab dialog moves and resizes with the tab control; i.e. if you move or resize the tab control, the tab dialog will be resized as well. The tab dialog isn't resized when you add the icons because the tab control's size and position haven't changed. Adding or removing tabs may require the tab dialog to be resized (if the number of rows changed), so there are actually two ways in v1 to cause the tab dialog to update its size:

Code: Select all

; #1: Move/resize the tab control.
GuiControl Move, %hTab3%, h201
; #2: Add or remove tabs (adding zero tabs also counts):
GuiControl,, %hTab3%
User avatar
jballi
Posts: 571
Joined: 29 Sep 2013, 17:34

Re: Large Icons in Tab Control

01 Apr 2018, 00:50

That did the trick. Thanks. As you implied, redraw is not the friend of the Tab3 control. If I run WinSet Redraw,,ahk_id %hTab3%, the GUI controls within the Tab3 control are not (re)drawn correctly.

Return to “Ask For Help”

Who is online

Users browsing this forum: aifritz, flyingDman, Getfree, Google [Bot], holahapi, NewberEnerNeeder1, TAC109, Villitz and 231 guests