Tabbing between user input fields in Child GUI Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Hol3yMol3y
Posts: 10
Joined: 10 Jun 2019, 04:08

Tabbing between user input fields in Child GUI

14 Jun 2019, 19:11

It seems that one of the quirks of using a Child GUI is that you can't use the tab key to jump between user input fields in the Child GUI.

I found a post from another user with a suggested workaround but the code he used only deals with one Child GUI - I will need multiple. I have set up an example using his code and added my second GUI. The first Child GUI works fine - the edit boxes can be tabbed through. The second Child GUI doesn't work.

This stems from the fact that I don't really understand how the code works (everything triggered by the Tab hotkey and the WinGet functions earlier in the code are a bit confusing to me).

Can anyone help me understand how I can make this code work for the second Child GUI also?

I have inserted MsgBoxes into the code to show when the WinGet function retrieves the list of onscreen controls.

Code: Select all

#SingleInstance, Force

GuiNumber := 1   

Gui, Main:New, +hwndhMain +LastFound
Gui, 1: New, +ParentMain +HWNDhChild -0x80000000 +0x40000000
Gui, 2: New, +ParentMain +HWNDhChild2 -0x80000000 +0x40000000

Gui, 1: Add, Text, x20 y10, This is Child GUI 1
Gui, 1: Add, Edit, x20 y30 w100 r1, Tab through this
Gui, 1: Add, Edit, x20 y60 w100 r1, Tab through this
Gui, 1: Color, White
Gui, 1: -Caption
Gui, 1: Show, x100 y100 w400 h400,

Gui, 2: Add, Text, x20 y10, This is Child GUI 2
Gui, 2: Add, Edit, x20 y30 w100 r1, Tab through this (doesn't work)
Gui, 2: Add, Edit, x20 y60 w100 r1, Tab through this (doesn't work)
Gui, 2: Add, Edit, x20 y90 w100 r1, Tab through this (doesn't work)
Gui, 2: Color, White
Gui, 2: -Caption
Gui, 2: Show, Hide x100 y100 w400 h400,

Gui, Main: Add, Button, +TabStop x250 y470 w100 r1 gPreviousGui, Previous
Gui, Main: Add, Button, +TabStop x350 y470 w100 r1 gNextGui, Next
Gui, Main: Show, w500 h500, Main Gui

Gui, 1: +Lastfound
WinGet, List, ControlList  ; get the list of controls in this GUI
List := RegExReplace(List, "Static\d+\n?") . "`n" ; remove all static controls from tab navigation
MsgBox, %List%
return

NextGui:
GuiNumber := GuiNumber + 1
If (GuiNumber = 3)
	GuiNumber := GuiNumber - 1
Else
	OldGui := GuiNumber - 1
GUi, %GuiNumber%: Show
Gui, %OldGui%: Hide

Gui, %GuiNumber%: +Lastfound
WinGet, List, ControlList  ; get the list of controls in this GUI
List := RegExReplace(List, "Static\d+\n?") . "`n" ; remove all static controls from tab navigation
MsgBox, %List%
return

PreviousGui:
GuiNumber := GuiNumber - 1
If (GuiNumber = 0)
	GuiNumber := GuiNumber + 1
Else
	OldGui := GuiNumber + 1
GUi, %GuiNumber%: Show
Gui, %OldGui%: Hide

Gui, %GuiNumber%: +Lastfound
WinGet, List, ControlList  ; get the list of controls in this GUI
List := RegExReplace(List, "Static\d+\n?") . "`n" ; remove all static controls from tab navigation
MsgBox, %List%
return


+Tab::
Tab::
Gui, +LastFound
Gui, Submit, NoHide
ControlGetFocus, ClassNN ; get the control that has the focus
ControlInQuestion := GetWindow(list, ClassNN, (A_ThisHotkey="tab"))
GuiControl, Focus, %ControlInQuestion% ; set focus to the next control

SendMessage, EM_SETSEL := 0x00B1, 0,-1, %ControlInQuestion% ; just to mimic select all text in edit control upon receiving the focus
return

GetWindow(List, ClassNN, next=true) {
	
	if next { ; get the next control in the Z-Order
		if !RegExMatch(list, ClassNN "\n(.+?)\n", ControlClass) ; get the next line in the list
			RegExMatch(list,"^(.+?)\n", ControlClass) ; get the first line in the list
	}else{ ; get the previous control in the Z-Order
		if !RegExMatch(list, "m)(?:^.+\n)?(.+)\n" ClassNN, ControlClass) ; get the previous line in the list
			RegExMatch(list,".+\n(.+)\n", ControlClass) ; get the last line in the list
	}
	
	return ControlClass1
}
Any help is much appreciated.
just me
Posts: 6290
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Tabbing between user input fields in Child GUI  Topic is solved

15 Jun 2019, 04:50

  1. The parent GUI controls should not overlap the child GUIs.
  2. You might want to try the WS_EX_CONTROLPARENT style.

Code: Select all

#SingleInstance, Force

; https://docs.microsoft.com/en-us/windows/desktop/winmsg/extended-window-styles
WS_EX_CONTROLPARENT := 0x00010000

GuiNumber := 1

Gui, Main:New, +hwndhMain +LastFound
Gui, 1: New, +ParentMain +HWNDhChild1 -0x80000000 +0x40000000 +E0x00010000
Gui, 2: New, +ParentMain +HWNDhChild2 -0x80000000 +0x40000000 +E0x00010000

Gui, 1: Add, Text, x20 y10, This is Child GUI 1
Gui, 1: Add, Edit, x20 y30 w100 r1, Tab through this
Gui, 1: Add, Edit, x20 y60 w100 r1, Tab through this
Gui, 1: Color, White
Gui, 1: -Caption
Gui, 1: Show, x100 y100 w300 h300

Gui, 2: Add, Text, x20 y10, This is Child GUI 2
Gui, 2: Add, Edit, x20 y30 w100 r1, Tab through this (doesn't work)
Gui, 2: Add, Edit, x20 y60 w100 r1, Tab through this (doesn't work)
Gui, 2: Add, Edit, x20 y90 w100 r1, Tab through this (doesn't work)
Gui, 2: Color, White
Gui, 2: -Caption
Gui, 2: Show, Hide x100 y100 w300 h300

Gui, Main: Add, Button, +TabStop x250 y470 w100 r1 gPreviousGui, Previous
Gui, Main: Add, Button, +TabStop x350 y470 w100 r1 gNextGui, Next
Gui, Main: Show, w500 h500, Main Gui

Return

NextGui:
   If (GuiNumber < 2) {
      OldNumber := GuiNumber
      GuiNumber++
      Gui, %GuiNumber%: Show
      Gui, %OldNumber%: Hide
   }
Return

PreviousGui:
   If (GuiNumber > 1) {
      OldNumber := GuiNumber
      GuiNumber--
      Gui, %GuiNumber%: Show
      Gui, %OldNumber%: Hide
   }
Return
P.S.: Or would a TAB3 control be an option?
Hol3yMol3y
Posts: 10
Joined: 10 Jun 2019, 04:08

Re: Tabbing between user input fields in Child GUI

15 Jun 2019, 05:36

Thank you so much! I have been trying to figure this out for so long and the solution was more simple than I could have ever imagined.

Also, I explored using Tab3 but I'd rather that the user has to move through the tabs in a set linear order, so the Child Gui method is working better for me.

Thanks again dude.

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, Bing [Bot], natester002, RickC, swagfag, vsub and 194 guests