Getting the name/number of the current tab in a GUI without having to submit

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
arkazal

Getting the name/number of the current tab in a GUI without having to submit

10 Jul 2018, 05:33

Is using Gui, Submit really the only way to get the name/number of the current tab? For example, I have 3 tabs.

Code: Select all

Gui, Add, Tab2, vTabNumber gLookup, View|Add|Edit
Gui, Add, Checkbox, vMyCheckbox, Sample checkbox
Gui, Tab, 2
Gui, Add, Edit, vMyEdit1 r1
Gui, Tab, 3
Gui, Add, DropDownList, vDropDownSelect
return

Lookup:
if (TabName == 3)
; Gui, Submit, NoHide
{
  dropdown :=
  Loop, Read, index.txt
  {
    dropdown := dropdown . A_LoopReadLine . "|"
  }
  GuiControl, , DropDownSelect, %dropdown%
}
return
Basically, I want to design this so that in Tab 2 (Add) you can enter some stuff and it saves to index.txt. When you click on Tab 3 (Edit), the DropDownList is repopulated with what you've personally added to index.txt so that you can edit the stuff in it. But I can only repopulate when I visit any other tab BESIDES the tab I want, which is just inefficient. And the only way I've found to remedy this is to remove the comment from the Gui, Submit, NoHide line so that literally every time you change a tab, your data is submitted... even though you might not want it to be?!

I've been using AutoHotKey for 10 years. I love it. And I'm new to GUIs. But so far, the fact that AHK only uses the tab you previous LEFT FROM is beyond infuriating. What use is this to me? And how can I work around this "feature"?
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Getting the name/number of the current tab in a GUI without having to submit

10 Jul 2018, 07:14

Hello arkazal!

I encoutered a little mistake: You are checking against "TabName", but the specified control variable is "TabNumber". Both variables should be called "TabName" and you have to check against the Tab titles "Add", "Edit", ... because the tab name is sumbitted, not the id.

Regarding the original problem, what is the problem with submitting the data after each tab change? It just copies the control elements contents available into your specified variables...
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Getting the name/number of the current tab in a GUI without having to submit

10 Jul 2018, 07:46

This will get the name of the current tab:

Code: Select all

GuiControlGet, CurrentTab,, TabNumber
MsgBox, % CurrentTab
If you want the tab number, add +AltSubmit to the tab control first:

Code: Select all

Gui, Add, Tab2, vTabNumber gLookup +AltSubmit, View|Add|Edit

GuiControlGet, CurrentTab,, TabNumber
MsgBox, % CurrentTab
If you don't want the tab control to be permanently using AltSubmit, you can add it later before retrieving the tab number, and then removing it afterwards like this:

Code: Select all

GuiControl, +AltSubmit, TabNumber
GuiControlGet, CurrentTab,, TabNumber
GuiControl, -AltSubmit, TabNumber
MsgBox, % CurrentTab
Example:

Code: Select all

#SingleInstance, Force

Gui, Margin, 10, 10
Gui, Add, Tab2, w400 h200 vTab gTab +Theme, View|Add|Edit

Gui, Tab
Gui, Add, Edit, wp r1 vEdit +0x800

Gui, Show, AutoSize, Example

GoSub, Tab
return

Tab:
	; Get Name
	GuiControlGet, TabName,, Tab
	
	; Get Number
	GuiControl, +AltSubmit, Tab
	GuiControlGet, TabNo,, Tab
	GuiControl, -AltSubmit, Tab
	
	; Change text of Edit control
	GuiControl,, Edit, % TabName " - " TabNo
return
arkazal

Re: Getting the name/number of the current tab in a GUI without having to submit

10 Jul 2018, 12:18

Alibaba, thanks for pointing that out. I had been switching back and forth between variable names while I had been trying AltSubmit.

TheDewd, you are indeed THE dude. Your code works brilliantly and is so darn easy even *I* can understand it :lol:
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Getting the name/number of the current tab in a GUI without having to submit

13 Jul 2018, 07:14

You could use SendMessage with TCM_GETCURSEL.

Code: Select all

;e.g. type one of these into the Run dialog (with AutoHotkey in Admin mode for sysdm.cpl)
;sysdm.cpl
;rundll32 shell32.dll,Options_RunDLL 1

q:: ;tab control - get selected tab index
ControlGet, hCtl, Hwnd,, SysTabControl321, A
SendMessage, 0x130B,,,, % "ahk_id " hCtl ;TCM_GETCURSEL := 0x130B
vNum := 1+ErrorLevel
MsgBox, % vNum
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 225 guests