AHK Gui tab styling

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

AHK Gui tab styling

12 Jul 2014, 23:00

Is there anyway to change the tab style so that it doesn't use white for the outline? I tried 0x8 but it gave me a thick horrible gray border around the non-active buttons. Thanks:

Code: Select all

Gui, -Caption  +ToolWindow -DPIScale
Gui, margin, 40,40
Gui, Color, c3366FF, c3366FF
Gui, Font, s40 cWhite bold
Gui, add, Tab2, w1200 h600 +buttons, Tab 1|Tab 2|Tab 3
Gui, show
return

esc:: exitapp
just me
Posts: 9450
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: AHK Gui tab styling

13 Jul 2014, 04:49

:arrow: Default Tab Control Message Processing -> WM_PAINT

I think this cannot be done without subclassing the control, processing the WM_PAINT message, and drawing the control by yourself.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: AHK Gui tab styling

13 Jul 2014, 11:51

In fact, if you add a Tab control with w0 h0 options, then you can use any control as the Tab buttons. An example:

Code: Select all

#NoEnv
SetBatchLines -1
#Include <Class_ImageButton> ; http://ahkscript.org/boards/viewtopic.php?f=6&t=1103

Gui, Color, White
Gui, Margin, 50, 50
Gui, Font, s16

AddImageTab("", "page1|page2|page3||page4")
	Gui, Tab, 1, 1
		Gui, Add, Text, xm Section Border w296 h200 0x201, page1
	Gui, Tab, 2
		Gui, Add, Button, xp w200, page2
	Gui, Tab, 3
		Gui, Add, Edit, xp w200 h200, page3
	Gui, Tab, 4
		Gui, Add, Radio, xp w200 h200, page4
	Gui, Tab

AddImageTab("xm y+0", "page1|page2||page3|page4", 1)
	Gui, Add, Text, x+10 yp-116 w210 h155 Border, 
	Loop, 4
	{
		Gui, Tab, %A_Index%
		Gui, Add, Text, xp+2 yp+2 wp-4 hp-4 0x201 cBlue, % "Page " A_Index
	}
Gui, Show
Return

GuiClose:
ExitApp

AddImageTab(Options, Pages, Vertical = False) {
	static HwndList := {}

	Opt1 := [3, 0xEEF1F4, 0xE4E9EF, "Black", 0,, 0xA5AFBF, 1]
	Opt2 := [3, 0xCDD6DF, 0xCDD6DF, "Black", 0,, 0xA5AFBF, 1]
	Opt3 := [3, 0xBEC7D6, 0xBEC7D6, "Black", 0,, 0xA5AFBF, 1]
	Opt4 := [3, 0xBEC7D6, 0xBEC7D6, "Black", 0,, 0xA5AFBF, 1]

	Gui, Add, Tab2, w0 h0 AltSubmit HwndHTab, % Pages ; Add an invisible Tab control
	Gui, Tab

	if !InStr(Pages, "||")
		Pages := Trim( StrReplace(Pages, "|", "||",, 1), "|" )

	TabIndex := 0
	Loop, Parse, Pages, |
	{
		if (A_LoopField = "") {
			GuiControl, Disable, %HBT%
			Continue
		}

		_Options := (A_Index = 1) ? Options " xp" : (Vertical ? "y+0" : "x+0")
		Gui, Add, Button, %_Options% HwndHBT g___AddImageTab_ChangeTab, % A_LoopField
			ImageButton.Create(HBT, Opt1, Opt2, Opt3, Opt4)

		TabIndex ++
		HwndList[HBT]                   := {TabIndex: TabIndex, TabHwnd: HTab}
		HwndList["HTab", HTab, TabIndex] := HBT
	}

	Return

	___AddImageTab_ChangeTab:
		GuiControlGet, focused_control, Focus
		GuiControlGet, focused_controlHwnd, Hwnd, %focused_control%
		TabIndex := HwndList[focused_controlHwnd+0]["TabIndex"]
		TabHwnd  := HwndList[focused_controlHwnd+0]["TabHwnd"]

		GuiControl, Choose, %TabHwnd%, |%TabIndex%
		
		For i, hwnd in HwndList["HTab"][TabHwnd]
			GuiControl, % (i = TabIndex) ? "Disable" : "Enable", %hwnd%
	Return
}
Screenshot
Image

Edit: Added support for default page.
Last edited by tmplinshi on 06 Jul 2019, 13:38, edited 1 time in total.
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: AHK Gui tab styling

13 Jul 2014, 18:22

Thanks for the code. Where should I put Class_ImageButton.ahk? I put it in the same folder as my script and added SetWorkingDir %A_ScriptDir% on line 3 of the example but got this error message:
---------------------------
test.ahk
---------------------------
Error at line 4.

Line Text: #Include <Class_ImageButton>
Error: Function library not found.

The program will exit.
---------------------------
OK
---------------------------
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: AHK Gui tab styling

13 Jul 2014, 21:35

Change to #Include Class_ImageButton.ahk will work for you.

I suggest put the function/class scripts to the Lib folder, because after then, you can call the functions from any scripts in any location, without copying to the script folder. #include <Class_ImageButton> means include Class_ImageButton.ahk from Lib folder. More details about #Include.
Last edited by tmplinshi on 13 Jul 2014, 21:41, edited 1 time in total.
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: AHK Gui tab styling

13 Jul 2014, 21:40

I've never ever used the Library Folder. I got this message with your suggested changed:
---------------------------
test.ahk
---------------------------
Error at line 4.

#Include file "Class_ImageButton.ahk" cannot be opened.

The program will exit.
---------------------------
OK
---------------------------
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: AHK Gui tab styling

13 Jul 2014, 21:44

Are you sure "Class_ImageButton.ahk" is in your script (test.ahk) folder?

#Include Class_ImageButton.ahk ; If Class_ImageButton.ahk is in the script folder
#Include <Class_ImageButton> ; If Class_ImageButton.ahk is in the Lib\ folder
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: AHK Gui tab styling

13 Jul 2014, 22:40

tmplinshi wrote:Are you sure "Class_ImageButton.ahk" is in your script (test.ahk) folder?

#Include Class_ImageButton.ahk ; If Class_ImageButton.ahk is in the script folder
Yes, I'm sure.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: AHK Gui tab styling

13 Jul 2014, 23:54

I guess this is because of your AutoHotkey.exe startup directory is not same as the script directory.
Try #Include Your_Script_Folder_Path\Class_ImageButton.ahk (e.g. #Include D:\scripts\Class_ImageButton.ahk)

=========================================================

Or try this one (It must work...)
test.ahk wrote:#Include <Class_ImageButton>

; If the script file path is D:\scripts\test.ahk,
; then put Class_ImageButton.ahk to D:\scripts\Lib\Class_ImageButton.ahk
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: AHK Gui tab styling

14 Jul 2014, 01:30

Thanks, using the folder's full path worked. Why is that necessary? I don't need to do it with my own includes.
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: AHK Gui tab styling

14 Jul 2014, 01:39

another example with custom tabs

Image
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: AHK Gui tab styling

14 Jul 2014, 03:00

@PuzzledGreatly Don't know. But you can check out MsgBox, % A_WorkingDir

@jNizM Nice!
User avatar
Klark92
Posts: 161
Joined: 18 Jan 2015, 19:33

Re: AHK Gui tab styling

19 May 2017, 13:55

@jNizM yes I didnt see the code ^^
Smart Kombo 1.0 | One of the best Knight Online's key combo program...
WilburBr
Posts: 15
Joined: 22 Jun 2019, 22:17

Re: AHK Gui tab styling

06 Jul 2019, 11:44

tmplinshi wrote: In fact, if you add a Tab control with w0 h0 options, then you can use any control as the Tab buttons. An example:

Code: Select all

#NoEnv
SetBatchLines -1
#Include <Class_ImageButton> ; http ahkscript.org /boards/viewtopic.php?f=6&t=1103  Broken Link for safety

Gui, Color, White
Gui, Margin, 50, 50
Gui, Font, s16

AddImageTab("", "page1|page2|page3|page4")
	Gui, Tab, 1, 1
		Gui, Add, Text, xm Section Border w296 h200 0x201, page1
	Gui, Tab, 2
		Gui, Add, Button, xp w200, page2
	Gui, Tab, 3
		Gui, Add, Edit, xp w200 h200, page3
	Gui, Tab, 4
		Gui, Add, Radio, xp w200 h200, page4
	Gui, Tab

AddImageTab("xm y+0", "page1|page2|page3|page4", 1)
	Gui, Add, Text, x+10 yp-116 w210 h155 Border, 
	Loop, 4
	{
		Gui, Tab, %A_Index%
		Gui, Add, Text, xp+2 yp+2 wp-4 hp-4 0x201 cBlue, % "Page " A_Index
	}
Gui, Show
Return

GuiClose:
ExitApp

AddImageTab(Options, Pages, Vertical = False) {
	static HwndList := {}

	Opt1 := [3, 0xEEF1F4, 0xE4E9EF, "Black", 0,, 0xA5AFBF, 1]
	Opt2 := [3, 0xCDD6DF, 0xCDD6DF, "Black", 0,, 0xA5AFBF, 1]
	Opt3 := [3, 0xBEC7D6, 0xBEC7D6, "Black", 0,, 0xA5AFBF, 1]
	Opt4 := [3, 0xBEC7D6, 0xBEC7D6, "Black", 0,, 0xA5AFBF, 1]

	Gui, Add, Tab2, w0 h0 AltSubmit HwndHTab, % Pages ; Add an invisible Tab control
	Gui, Tab

	Loop, Parse, Pages, |
	{
		_Options := (A_Index = 1) ? Options " Disabled xp" : (Vertical ? "y+0" : "x+0")
		Gui, Add, Button, %_Options% HwndHBT g___AddImageTab_ChangeTab, % A_LoopField
			ImageButton.Create(HBT, Opt1, Opt2, Opt3, Opt4)

		HwndList[HBT]                   := {TabIndex: A_Index, TabHwnd: HTab}
		HwndList["HTab", HTab, A_Index] := HBT
	}

	Return

	___AddImageTab_ChangeTab:
		GuiControlGet, focused_control, Focus
		GuiControlGet, focused_controlHwnd, Hwnd, %focused_control%
		TabIndex := HwndList[focused_controlHwnd+0]["TabIndex"]
		TabHwnd  := HwndList[focused_controlHwnd+0]["TabHwnd"]

		GuiControl, Choose, %TabHwnd%, |%TabIndex%
		
		For i, hwnd in HwndList["HTab"][TabHwnd]
			GuiControl, % (i = TabIndex) ? "Disable" : "Enable", %hwnd%
	Return
}
Screenshot
Image Broken Link for safety
Thanks :dance: It was exactly what I was looking for.

Is there any way to set the tab "page 2" as default? I tried to put two "||" but only creates a new empty tab button .

thank you
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: AHK Gui tab styling

06 Jul 2019, 13:44

@WilburBr Added. I've updated the code in the previous reply.
WilburBr
Posts: 15
Joined: 22 Jun 2019, 22:17

Re: AHK Gui tab styling

07 Jul 2019, 12:43

tmplinshi wrote: @WilburBr Added. I've updated the code in the previous reply.

Thank you very much, tmplinshi.
:D :D

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada and 229 guests