Problem with GUI Tabs

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
KilliK
Posts: 255
Joined: 10 Mar 2016, 21:19

Problem with GUI Tabs

19 Jan 2018, 02:17

Hello.
I have created a GUI script based on an older script I found here. It is basically a list of all my hotkeys from all my scripts, since I cant remember them all.
I have almost completed the scipt but I encountered two problems which I cant resolve:

1.Whenever I click one of the tabs from the top row of the tabbar, the top row swaps with the bottom row.
I dont want that, I want the tabs to remain in the same position they appear to be, whenever I start the script and run the GUI.
Here is an example:

Before i click tab in top row
Image
After I clicked it
Image

Ιf I click one of the tabs from the top row, the top row becomes bottom. the same will happen again if I click another tab from the top row.
I only want all the tabs to have the same position like in the first photo.

2.How can I make the active tab colorized with the blue color (its background, border, whatever is possible), so it is distinguishable from the others tabs? I want only the tab part with the text tile, not the entire listview/window.
something like this:
Image

Script's code. i am also attaching the file.

Code: Select all

;#Warn
#NoEnv
#Persistent
#SingleInstance Force
DetectHiddenWindows, On
SetTitleMatchMode, 2
SendMode, Input
;============================================================;


;============================================================;
;HOTKEYS LIST OF ALL SCRIPTS
;============================================================;

;Open Hotkeys List
F1::


MODIFIED=20140605
;- Listview   >>>   ADD_NEW  / MODIFY / DELETE / SEARCH

MainWindowTitle=Hotkeys
transform,T,chr,09
delim = `,
first1:=0

gosub,test1    ;-- create 2 text-files for 2 ListViews  ( test )

Gui,2:default
Gui,2: Font,CDefault,Fixedsys
Gui,2: Margin, 10, 10

Tabnumber:=1
    gui,2:add, Tab2, x10 y10 w580 h128 gtabchange vTabnumber AltSubmit, Manager|Organizer|Positions|Software|Windows|Hearthstone|Overwatch|Heroes of the Storm

        gui,2:tab, Manager
            gui,2:add, listview,x10 y55 w580 h500 grid cWhite backgroundteal hwndLV1 vLV1 gListViewEvents +altsubmit -multi, Keys|AHK|Function
            gosub,fill1
            gosub,width1
           ;Gui,2:add,button, x10  y450 gPrintLV1,Print
            Gui,2:Add, Button, x10 y570 w100 vaddnew1 gAddNew1,ADD NEW
            Gui,2:Add, Edit, x140 y570 w300 gFind vSrch1,
            Gui,2:Add, Button, x470 y570 w100 vexitgui1 gexitgui, EXIT          


        gui,2:tab, Organizer
            gui,2:add, listview,x10 y55 w580 h500 grid cWhite backgroundteal hwndLV2 vLV2 gListViewEvents +altsubmit -multi, Keys|AHK|Function
            gosub,fill2
            gosub,width1
           ;Gui,2:add,button, x10 y450 gPrintLV1,Print
            Gui,2:Add, Button, x10 y570 w100 vaddnew2 gAddNew1,ADD NEW
            Gui,2:Add, Edit, x140 y570 w300 gFind vSrch2,
            Gui,2:Add, Button, x470 y570 w100 vexitgui2 gexitgui, EXIT

            
        gui,2:tab, Positions
            gui,2:add, listview,x10 y55 w580 h500 grid cWhite backgroundteal hwndLV3 vLV3 gListViewEvents +altsubmit -multi, Keys|AHK|Function
            gosub,fill3
            gosub,width1
           ;Gui,2:add,button, x10 y450 gPrintLV1,Print
            Gui,2:Add, Button, x10 y570 w100 vaddnew3 gAddNew1,ADD NEW
            Gui,2:Add, Edit, x140 y570 w300 gFind vSrch3,
            Gui,2:Add, Button, x470 y570 w100 vexitgui3 gexitgui, EXIT

            
        gui,2:tab, Software
            gui,2:add, listview,x10 y55 w580 h500 grid cWhite backgroundteal hwndLV4 vLV4 gListViewEvents +altsubmit -multi, Keys|AHK|Function
            gosub,fill4
            gosub,width1
           ;Gui,2:add,button, x10 y450 gPrintLV1,Print
            Gui,2:Add, Button, x10 y570 w100 vaddnew4 gAddNew1,ADD NEW
            Gui,2:Add, Edit, x140 y570 w300 gFind vSrch4,
            Gui,2:Add, Button, x470 y570 w100 vexitgui4 gexitgui, EXIT
            
            
        gui,2:tab, Windows
            gui,2:add, listview,x10 y55 w580 h500 grid cWhite backgroundteal hwndLV5 vLV5 gListViewEvents +altsubmit -multi, Keys|AHK|Function
            gosub,fill5
            gosub,width1
           ;Gui,2:add,button, x10 y450 gPrintLV1,Print
            Gui,2:Add, Button, x10 y570 w100 vaddnew5 gAddNew1,ADD NEW
            Gui,2:Add, Edit, x140 y570 w300 gFind vSrch5,
            Gui,2:Add, Button, x470 y570 w100 vexitgui5 gexitgui, EXIT   


        gui,2:tab, Hearthstone
            gui,2:add, listview,x10 y55 w580 h500 grid cWhite backgroundteal hwndLV6 vLV6 gListViewEvents +altsubmit -multi, Keys|AHK|Function
            gosub,fill6
            gosub,width1
           ;Gui,2:add,button, x10 y450 gPrintLV1,Print
            Gui,2:Add, Button, x10 y570 w100 vaddnew6 gAddNew1,ADD NEW
            Gui,2:Add, Edit, x140 y570 w300 gFind vSrch6,
            Gui,2:Add, Button, x470 y570 w100 vexitgui6 gexitgui, EXIT    
            
            
        gui,2:tab, Overwatch
            gui,2:add, listview,x10 y55 w580 h500 grid cWhite backgroundteal hwndLV7 vLV7 gListViewEvents +altsubmit -multi, Keys|AHK|Function
            gosub,fill7
            gosub,width1
           ;Gui,2:add,button, x10 y450 gPrintLV1,Print
            Gui,2:Add, Button, x10 y570 w100 vaddnew7 gAddNew1,ADD NEW
            Gui,2:Add, Edit, x140 y570 w300 gFind vSrch7,
            Gui,2:Add, Button, x470 y570 w100 vexitgui7 gexitgui, EXIT                   
            
            
        gui,2:tab, Heroes of the Storm
            gui,2:add, listview,x10 y55 w580 h500 grid cWhite backgroundteal hwndLV8 vLV8 gListViewEvents +altsubmit -multi, Keys|AHK|Function
            gosub,fill8
            gosub,width1
           ;Gui,2:add,button, x10 y450 gPrintLV1,Print
            Gui,2:Add, Button, x10 y570 w100 vaddnew8 gAddNew1,ADD NEW
            Gui,2:Add, Edit, x140 y570 w300 gFind vSrch8,
            Gui,2:Add, Button, x470 y570 w100 vexitgui8 gexitgui, EXIT        
        
        
;to exit variable xreiazetai tin katalixi _TT gia na trexei to tooltip    
exitgui1_TT := "Exit" 
exitgui2_TT := "Exit"
exitgui3_TT := "Exit"
exitgui4_TT := "Exit" 
exitgui5_TT := "Exit"
exitgui6_TT := "Exit"
exitgui7_TT := "Exit" 
exitgui8_TT := "Exit"

addnew1_TT := "Add New"
addnew2_TT := "Add New"
addnew3_TT := "Add New"
addnew4_TT := "Add New"
addnew5_TT := "Add New"
addnew6_TT := "Add New"
addnew7_TT := "Add New"
addnew8_TT := "Add New"


OnMessage(0x200, "WM_MOUSEMOVE") ;show tooltip

gui,2: show, x980 y420 w600 h610, %MainWindowTitle%
gosub,tabchange
Return

;valtin os adeia "gnull" subroutine sta text boxes mono, gia na trexei to tooltip
null:
Return

2Guiclose:
2GuiEscape:
exitgui:
Gui, Destroy ;closes gui without exiting script
Return

width1:
   T1=200
   T2=76
   T3=300
   LV_ModifyCol(1,T1)
   LV_ModifyCol(2,T2)
   LV_ModifyCol(3,T3)
  ;LV_ModifyCol(2,"Integer")
Return

;-------------------------------------------------------------------------------------
tabchange:
GuiControlGet, Tabnumber
GuiControl,2:Focus,srch%tabnumber%
Return
;-------------------------------------------------------------------------------------


;---------------- SEARCH -------------------
Find:
Gui,2: Submit, Nohide
Gui,2:listview, LV%Tabnumber%
Fx=%A_WorkingDir%\Hotkeys%tabnumber%.txt
src:= % srch%Tabnumber%
if (SRC="")
   {
   goto,Fill%Tabnumber%
   Return
   }
LV_Delete()
  loop,read,%fx%
  {
  LR=%A_loopReadLine%
  if SRC<>
     {
     if LR contains %src%
       {
       stringsplit,C,A_LoopReadLine,%delim%
       LV_Add("",C1,C2,C3)
       }
     }
  else
   continue
   }
LV_Modify(LV_GetCount(), "Vis")
if (SRC="")
  goto,Fill%Tabnumber%
Return


;------------------- LISTVIEW --------------
ListViewEvents:
Gui,2:default
Gui,2:listview, LV%Tabnumber%

    if(A_GuiEvent == "Normal")
         {
         LV_GetText(C1, A_EventInfo, 1)
         LV_GetText(C2, A_EventInfo, 2)
         LV_GetText(C3, A_EventInfo, 3)
         Clipboard := C1 " - " C2 " - " C3
         }

    if(A_GuiEvent == "DoubleClick")
        {
        LV_GetText(C2, A_EventInfo, 2)
        Send % C2
        /*
        stringmid,url1,c2,1,7
        stringmid,pth1,c2,2,2
        if ((url1="http://") or (pth1=":\"))
          run,%c2%
          */
        Return
        }


    if(A_GuiEvent == "RightClick")
        {
        LV_GetText(C1, A_EventInfo, 1)
        LV_GetText(C2, A_EventInfo, 2)
        LV_GetText(C3, A_EventInfo, 3)
        gosub,Modify1
        Return
        }

    if A_GuiEvent=K
       {
       GetKeyState,state,DEL        ;- << DELETE
       if state=D
         {
         RowNumber:=LV_GetNext()
         LV_Delete(RowNumber)
         gosub,Modify2
         Return
        }
      Return
      }
Return
;--------------------------------------------------------------



;----------------   MODIFY  ----------------
Modify1:
Gui,3: +AlwaysonTop
Gui,3: Font, s10, Verdana
gui, 3:listview, LV%Tabnumber%
    Gui,3:add, edit, w300 h30 vC1, %C1%
    Gui,3:add, edit, w300 h30 vC2, %C2%
    Gui,3:add, edit, w300 h30 vC3, %C3%    

    Gui,3: Add,Button,   x12 gACCEPT1 default, Accept
    Gui,3: Add,Button,   x+4 gCANCEL1, Cancel
Gui,3:show,center, Modify ;LV_Modify
Return

accept1:
Gui,2:default
Gui,3:submit,nohide
gui 3:listview, LV%Tabnumber%
RowNumber := LV_GetNext()
If ( RowNumber = 0 ) {
Gui,3:destroy
c1:=
c2:=
c3:=
MsgBox,,ERROR,You clicked an empty row
}
else {
c1:= % c1
c2:= % c2
c3:= % c3
lv_modify(rownumber, "col1" , C1 )
lv_modify(rownumber, "col2" , C2 )
lv_modify(rownumber, "col3" , C3 )
gosub,modify2
Gui,3:destroy
}
Return

cancel1:
3Guiclose:
Gui,3:destroy
Return
;-----------------------------------------------------------------


;----------------   ADD NEW  ----------------
ADDNEW1:
Gui,4: +AlwaysonTop
Gui,4: Font, s10, Verdana
Gui,4:listview, LV%Tabnumber%
    Gui,4:add, Text,, Keys
    Gui,4:add, edit, w300 h30 vC1,
    Gui,4:add, Text,, AHK
    Gui,4:add, edit, w300 h30 vC2,
    Gui,4:add, Text,, Function
    Gui,4:add, edit, w300 h30 vC3,

    Gui,4: Add,Button,   x12 gACCEPT4 default, Accept
    Gui,4: Add,Button,   x+4 gCANCEL4, Cancel
Gui,4:show,center,Add New
Return

accept4:
Gui,2:default
Gui,4:submit,nohide
Gui,4:listview, LV%Tabnumber%
Fx=%A_WorkingDir%\Hotkeys%tabnumber%.txt
Fileappend,%c1%%delim%%c2%%delim%%c3%`r`n,%fx%
gosub,fill%tabnumber%
Gui,4:destroy
Return

cancel4:
4Guiclose:
Gui,4:destroy
Return
;-----------------------------------------------------------------



;------------------ FILL ----------------------------
Fill1:
gui,2:listview, listview%Tabnumber%
LV_Delete()
loop,read,%F1%
  {
  LR=%A_loopReadLine%
  if LR=
     continue
          C1 =
          C2 =
          C3 =
         stringsplit,C,LR,%delim%,
   LV_Add("", c1,c2,c3)
  }
LV_ModifyCol(1, "Sort CaseLocale")   ; or "Sort CaseLocale"
LV_Modify(LV_GetCount(), "Vis")      ;scrolls down
Return


Fill2:
gui, 2:listview, listview%Tabnumber%
LV_Delete()
loop,read,%F2%
  {
  LR=%A_loopReadLine%
  if LR=
     continue
          C1 =
          C2 =
          C3 =
         stringsplit,C,LR,%delim%,
   LV_Add("", c1,c2,c3)
  }
LV_ModifyCol(1, "Sort CaseLocale")   ; or "Sort CaseLocale"
LV_Modify(LV_GetCount(), "Vis")      ;scrolls down
Return

Fill3:
gui, 2:listview, listview%Tabnumber%
LV_Delete()
loop,read,%F3%
  {
  LR=%A_loopReadLine%
  if LR=
     continue
          C1 =
          C2 =
          C3 =
         stringsplit,C,LR,%delim%,
   LV_Add("", c1,c2,c3)
  }
LV_ModifyCol(1, "Sort CaseLocale")   ; or "Sort CaseLocale"
LV_Modify(LV_GetCount(), "Vis")      ;scrolls down
Return

Fill4:
gui,2:listview, listview%Tabnumber%
LV_Delete()
loop,read,%F4%
  {
  LR=%A_loopReadLine%
  if LR=
     continue
          C1 =
          C2 =
          C3 =
         stringsplit,C,LR,%delim%,
   LV_Add("", c1,c2,c3)
  }
LV_ModifyCol(1, "Sort CaseLocale")   ; or "Sort CaseLocale"
LV_Modify(LV_GetCount(), "Vis")      ;scrolls down
Return

Fill5:
gui,2:listview, listview%Tabnumber%
LV_Delete()
loop,read,%F5%
  {
  LR=%A_loopReadLine%
  if LR=
     continue
          C1 =
          C2 =
          C3 =
         stringsplit,C,LR,%delim%,
   LV_Add("", c1,c2,c3)
  }
LV_ModifyCol(1, "Sort CaseLocale")   ; or "Sort CaseLocale"
LV_Modify(LV_GetCount(), "Vis")      ;scrolls down
Return

Fill6:
gui,2:listview, listview%Tabnumber%
LV_Delete()
loop,read,%F6%
  {
  LR=%A_loopReadLine%
  if LR=
     continue
          C1 =
          C2 =
          C3 =
         stringsplit,C,LR,%delim%,
   LV_Add("", c1,c2,c3)
  }
LV_ModifyCol(1, "Sort CaseLocale")   ; or "Sort CaseLocale"
LV_Modify(LV_GetCount(), "Vis")      ;scrolls down
Return

Fill7:
gui,2:listview, listview%Tabnumber%
LV_Delete()
loop,read,%F7%
  {
  LR=%A_loopReadLine%
  if LR=
     continue
          C1 =
          C2 =
          C3 =
         stringsplit,C,LR,%delim%,
   LV_Add("", c1,c2,c3)
  }
LV_ModifyCol(1, "Sort CaseLocale")   ; or "Sort CaseLocale"
LV_Modify(LV_GetCount(), "Vis")      ;scrolls down
Return

Fill8:
gui,2:listview, listview%Tabnumber%
LV_Delete()
loop,read,%F8%
  {
  LR=%A_loopReadLine%
  if LR=
     continue
          C1 =
          C2 =
          C3 =
         stringsplit,C,LR,%delim%,
   LV_Add("", c1,c2,c3)
  }
LV_ModifyCol(1, "Sort CaseLocale")   ; or "Sort CaseLocale"
LV_Modify(LV_GetCount(), "Vis")      ;scrolls down
Return


;---------------------------------------------------





;------------------- Modify Text -------------------------
Modify2:
Fx=%A_WorkingDir%\Hotkeys%tabnumber%.txt
ifexist,%fx%
   filedelete,%fx%
ControlGet,AA,List,,SysListView32%tabnumber%,%MainWindowTitle%        ;<< the correct name of listview
if aa<>
 {
 stringreplace,AA,AA,%t%,%delim%,all                                   ;<< replaces TAB with Delimiter
 stringreplace,AA,AA,`n,`r`n,all
 ;msgbox, 262208, ,%aa%
 AA = %AA%`n
 fileappend,%AA%,%fx%
 aa=
 Return
 }
Return
;------------------------------------------------------------------





;------------------- PRINT-Listview -------------------------
PrintLv1:
FileTest=%A_WorkingDir%\PrintListview55.txt
ifexist,%filetest%
   filedelete,%filetest%
ControlGet,AA,List,,SysListView32%tabnumber%,%MainWindowTitle%        ;<< the correct name of listview
if aa<>
 {
 stringreplace,AA,AA,%t%,%delim%,all                                   ;<< replaces TAB with Delimiter
 stringreplace,AA,AA,`n,`r`n,all
 ;msgbox, 262208, ,%aa%
 fileappend,%AA%,%filetest%
 aa=
 run,%filetest%
 Return
 }
Return
;------------------------------------------------------------------




;--- create a testfile ---------------
test1:
;delim = `,
F1=%A_WorkingDir%\Hotkeys1.txt
ifnotexist,%f1%
{
  e1=
  (Ltrim Join`r`n
  Control Alt%delim%^!%delim%patas dio koumpia
  Left mouse click%delim%Lclick%delim%patas mouse klik
  )
Fileappend,%e1%`r`n,%f1%
}

F2=%A_WorkingDir%\Hotkeys2.txt
ifnotexist,%f2%
{
  e2=
  (Ltrim Join`r`n
  Control Alt%delim%^!%delim%patas dio koumpia
  Left mouse click%delim%Lclick%delim%patas mouse klik
  )
Fileappend,%e2%`r`n,%f2%
}

F3=%A_WorkingDir%\Hotkeys3.txt
ifnotexist,%f3%
{
  e3=
  (Ltrim Join`r`n
  Control Alt%delim%^!%delim%patas dio koumpia
  Left mouse click%delim%Lclick%delim%patas mouse klik
  )
Fileappend,%e3%`r`n,%f3%
}

e1=
e2=
e3=
Return
;--- end create a testfile -----------


;============================================================;
;FUNCTIONS
;============================================================;

;show tooltip over GUI elements
WM_MOUSEMOVE(){
	static CurrControl, PrevControl, _TT
	CurrControl := A_GuiControl
	If (CurrControl <> PrevControl){
			SetTimer, DisplayToolTip, -100 	; shorter wait, shows the tooltip quicker
			PrevControl := CurrControl
	}
	Return
	
	DisplayToolTip:
	try
			ToolTip % %CurrControl%_TT
	catch
			ToolTip
	SetTimer, RemoveToolTip, -3000
	Return
	
	RemoveToolTip:
	ToolTip
	Return
}
Attachments
Manager.ahk
(29.57 KiB) Downloaded 17 times
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Problem with GUI Tabs

19 Jan 2018, 03:54

[sOT] If you/others are preferring a more visual approach this might be of interest as well :arrow: https://autohotkey.com/boards/viewtopic ... 22&t=42683 [/sOT]
Spoiler
AFAIK that row-swap is a standard Windows behaviour for these type of controls (I hate that as well especially searching some "properties" dialogue boxes). TBH, I've no idea how to force those to remain static.
Isn't the coloring of the selected tab label/string possible via GuiControl, Font ???
User avatar
KilliK
Posts: 255
Joined: 10 Mar 2016, 21:19

Re: Problem with GUI Tabs

19 Jan 2018, 05:22

I ll check that GuiControl comman, changing the font color is a better solution.
but how can the script determine when the tab is active or clicked? what's the command for that?
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Problem with GUI Tabs

19 Jan 2018, 05:34

KilliK wrote:I ll check that GuiControl comman, changing the font color is a better solution.
but how can the script determine when the tab is active or clicked? what's the command for that?
Probably A_GuiEvent, A_EventInfo, OnMessage, GuiControlGet, OutputVar, Focus ...
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: Problem with GUI Tabs

19 Jan 2018, 15:07

Just short , make a small example with 2-3 Tabs for test
see special > listview%Tabnumber%

;ListViewEvents:
; gui, mainui:listview, listview%Tabnumber%

Code: Select all

;-------- http://ahkscript.org/boards/viewtopic.php?f=5&t=3656 ---
MODIFIED=20140531
Tabnumber:=1
    gui, mainui:new, hwndmainui, ListViews On Tab2
    gui,add, Tab2, gtabchange vTabnumber AltSubmit, one|two|three|four
        gui,tab, one
            gui,add, listview, r5 vlistview1 gListViewEvents +altsubmit -multi, col1|col2
            LV_Add("", "bob", "harry")
            LV_Add("", "first", "111111111")
            gosub,width1
        gui,tab, two
            gui,add, listview, r5 vlistview2 gListViewEvents +altsubmit -multi, col1|col2
            LV_Add("", "george", "harvey")
            LV_Add("", "second", "222222")
        gui, tab, three
            gui,add, listview, r5 vlistview3 gListViewEvents +altsubmit -multi, col1|col2
            LV_Add("", "michael", "richard")
            LV_Add("", "third", "33333333")
        gui, tab, four
            gui,add, listview, r5 vlistview4 gListViewEvents +altsubmit -multi, col1|col2
            LV_Add("", "harold", "marcel")
            LV_Add("", "fourth", "44444")
    gui, show
gosub,tabchange
RETURN

mainuiGuiclose:
exitapp

width1:
  T1=70
   T2=140
   LV_ModifyCol(1,T1)
   LV_ModifyCol(2,T2)
   LV_ModifyCol(2,"Integer")
return

; -------------------------------------------------------------------------------------
tabchange:
  GuiControlGet, Tabnumber
Return
;=======================================================================================

ListViewEvents:
   gui, mainui:listview, listview%Tabnumber%
    if(A_GuiEvent == "Normal"){
    LV_GetText(firstcol, A_EventInfo, 1)
    LV_GetText(secondcol, A_EventInfo, 2)
    msgbox, %firstcol% : %secondcol%
    }
RETURN
;================== END script ==========================================================
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Problem with GUI Tabs

19 Jan 2018, 20:24

Check this library out for some tab functions.
https://github.com/AHK-just-me/TC_EX
User avatar
KilliK
Posts: 255
Joined: 10 Mar 2016, 21:19

Re: Problem with GUI Tabs

20 Jan 2018, 07:29

thank you all for your help.
I found a simple code which colorizes the active tab, thanks to this post:

https://autohotkey.com/board/topic/9459 ... e-gui-tab/

I tweaked the script and now is complete.
again thank you for your time.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 223 guests