Can't interact with controls of a Child GUI Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Can't interact with controls of a Child GUI

Post by Nightwolf85 » 24 Aug 2020, 11:02

Hello,
I'm not sure if this is just me not understanding the relationship between a parent and child window, or something wrong with my computer. I am hoping this is just a simple thing I am doing wrong, or even better it works as expected for everyone else, and it is just my computer being strange.

With the following simplified code, I get the look I want of a window within a window, but I can not activate the child window, or edit its controls.

Code: Select all

#NoEnv
#SingleInstance, Force

GUI, Main:New, +Resize
GUI, Add, Text, , AHK Version - %A_Ahkversion%
GUI, Color, B0B0B0
GUI, Main:Show, w600 h400, Main


GUI, Child:New, +ParentMain
GUI, Add, Edit, , Can you edit me?
GUI, Add, Edit, , How about me?
GUI, Child:Show, w200, Child
Return

MainGUIClose:
ExitApp
This is the minimal amount of code I can think of that shows the problem I'm having. To show the problem here is a GIF of what it looks like for me:
https://giant.gfycat.com/SpanishIllfatedDowitcher.webm

In the GIF I am clicking and dragging trying to select the text, and while you can see that I moved the Child window it is never activating.

Is this normal behavior? and I just mis-understood the purpose of having a Parent-Child GUI relationship? I can't seem to find out very much about how it is supposed to function, outside of using the +Parent command to set it up.

Any input would be appreciated.

Thank you.

RubbeH
Posts: 49
Joined: 13 Jul 2020, 08:40

Re: Can't interact with controls of a Child GUI

Post by RubbeH » 25 Aug 2020, 06:21

This might not be helpful, but if copy your code and minimize the Child gui and immediately maximize it again, I can write in the first edit-box.

If I remove +ParentMain

Code: Select all

GUI, Child:New,
GUI, Add, Edit, , Can you edit me?
GUI, Add, Edit, , How about me?
GUI, Child:Show, w200, Child
it seems to work tho?

Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Can't interact with controls of a Child GUI

Post by Nightwolf85 » 25 Aug 2020, 08:59

RubbeH wrote:
25 Aug 2020, 06:21
This might not be helpful, but if copy your code and minimize the Child gui and immediately maximize it again, I can write in the first edit-box.
I noticed that as well, it is strange.
RubbeH wrote:
25 Aug 2020, 06:21
If I remove +ParentMain
it seems to work tho?
It does work, it just no longer confines the Child GUI to be within the boundaries of the Main GUI. This is probably what I will have to do, it just wasn't the look I was going for.


Also I found that if I add -Caption to the Child window I can edit the controls, but obviously lose the title, and ability to move the child window around. Which I would prefer to keep, it seems that even +ToolWindow doesn't allow activation.

Code: Select all

#NoEnv
#SingleInstance, Force

GUI, Main:New, +Resize +HWNDparentID
GUI, Add, Text, , AHK Version - %A_Ahkversion%
GUI, Color, B0B0B0
GUI, Main:Show, w600 h400, Main


GUI, Child:New, +HWNDchildID +ParentMain -Caption
GUI, Add, Edit, , Can you edit me?
GUI, Add, Edit, , How about me?
GUI, Child:Show, w200, Child
Return

MainGUIClose:
ExitApp
Thank you for the suggestions, appreciated.

teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: Can't interact with controls of a Child GUI  Topic is solved

Post by teadrinker » 25 Aug 2020, 15:44

You can use this way:

Code: Select all

GUI, Main:New, +Resize +HWNDparentID
GUI, Add, Text, , AHK Version - %A_Ahkversion%
GUI, Color, B0B0B0
GUI, Main:Show, w600 h400, Main


GUI, Child:New, +HWNDchildID
GUI, Add, Edit, , Can you edit me?
GUI, Add, Edit, , How about me?

DllCall("SetParent", "Ptr", childID, "Ptr", parentID)
GUI, Child:Show, x100 y100 w200, Child
Return

MainGUIClose:
ExitApp

Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Can't interact with controls of a Child GUI

Post by Nightwolf85 » 26 Aug 2020, 06:18

teadrinker wrote:
25 Aug 2020, 15:44
You can use this way:
Thank you very much!! that does seem to work. I wonder why it behaves different if done that way.

teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: Can't interact with controls of a Child GUI

Post by teadrinker » 26 Aug 2020, 09:52

Nightwolf85 wrote: I wonder why it behaves different if done that way.
Unlike the GUI option +Parent the winapi SetParent does not modify the WS_CHILD or WS_POPUP window styles of the window whose parent is being changed, so there is the difference.

Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Can't interact with controls of a Child GUI

Post by Nightwolf85 » 26 Aug 2020, 11:46

teadrinker wrote:
26 Aug 2020, 09:52
Unlike the GUI option +Parent the winapi SetParent does not modify the WS_CHILD or WS_POPUP window styles of the window whose parent is being changed, so there is the difference.
Thank you for doing the research there, I was not looking up the correct documentation to find that!

So basically it isn't a true child window, because it still has the WS_POPUP style instead of the WS_CHILD style...?

Works for me, Thank you again!

garry
Posts: 3769
Joined: 22 Dec 2013, 12:50

Re: Can't interact with controls of a Child GUI

Post by garry » 26 Aug 2020, 15:38

@teadrinker thank you , I tried this example

Code: Select all

;- modified = 20200826
;- created  = 20200426
;-- example PARENT_CHILD , use ESC to close GUI-2/3 or remove caption or add Close-button
;-  VideoPlay with vlc.exe
#warn
#noenv
Gui,1:default
Gui,1: -DPIScale
SS_REALSIZECONTROL := 0x40
wa:=A_screenwidth,ha:=A_screenHeight,xx=100
Gui,1: +HwndAId  +0x2000000                                    ;- < A        
;---------------
Gui,1:Font,s10 cBlack,Lucida Console
;Gui,1:Color,C8D0D4,Black                  ;- gray
Gui,1:Color,Black,Black
;---------------
x:=(wa*1)/xx,y:=(ha*1)/xx,w:=(wa*4)/xx,h:=(ha*2.3)/xx
Gui,1: add, Button ,x%x% y%y% w%w% h%h% gChilddestroyall vA1,1-MAIN
y:=(ha*4)/xx
Gui,1: Add, Button ,x%x% y%y%  w%w% h%h% gAdd2    vA2, 2-Video
y:=(ha*7)/xx
Gui,1: Add, Button ,x%x% y%y%  w%w% h%h% gAdd3    vA3, 3-Picture
;---------------
x:=(wa*6)/xx,y:=(ha*.1)/xx,w:=(wa*58)/xx,h:=(ha*54)/xx
Gui,1:Add,picture, x%x% y%y% w%w%  h%h% ,C:\windows\web\wallpaper\windows\img0.jpg
;---------------
x:=(wa*8)/xx,y:=(ha*1)/xx,w:=(wa*6)/xx,h:=(ha*2.3)/xx
Gui,1: Add, Button, x%x% y%y% w%w%  h%h%   gS1, Some -1
y:=(ha*4)/xx
Gui,1: Add, Button, x%x% y%y% w%w%  h%h%   gO1, Other-1
;----------------
x:=(wa*1)/xx,y:=(ha*1)/xx,w:=(wa*66)/xx,h:=(ha*56)/xx
Gui,1: Show,x%x% y%y% w%w%  h%h%,PARENT_CHILD ( use ESC to close GUI-2/3 )
Guicontrol,1:disable ,A1
return
;------------------
GuiClose:
ExitApp
;------------------
S1:
msgbox,SOME-1
return
O1:
msgbox,OTHER-1
return
;======================================================
;------------------------------------------------------
childdestroyall:
Gui,2:destroy
Gui,3:destroy
Guicontrol,1:disable,A1
Guicontrol,1:enable ,A2
Guicontrol,1:enable ,A3
return
;------------------------------------------------------
;============= 2nd VIDEOPLAY vlc.exe ==================
Add2:
Gui,1:submit,nohide
Gui,2: default
Gui,2: -DPIScale +HwndBId  -Caption -Border +alwaysontop     ;- < B
SS_REALSIZECONTROL := 0x40
Gui,2: Color,Black,Black 
HK2=Esc
  Hotkey,%hk2%,Remove2,ON
;----------
url=https://www.youtube.com/embed/sraZaL6jylM?autoplay=1
;xxb=Shell.Explorer     ;- IExplorer
xxb=VideoLAN.VLCPlugin.2

x:=(wa*.1)/xx,y:=(ha*.1)/xx,w:=(wa*58)/xx,h:=(ha*54)/xx
Gui,2:Add,ActiveX,  x%x% y%y% w%w%  h%h%  vVlcx,%xxb%
;Gui,2:Add,ActiveX,  x%x% y%y% w%w%  h%h%  vWB,%xxb%
;wb.Visible := true 
;WB.Silent  := True
;WB.Navigate(URL)
VLCx.playlist.add(URL)
VLCx.playlist.play()
;----------
x:=(wa*6)/xx,y:=(ha*.1)/xx,w:=(wa*59)/xx,h:=(ha*55)/xx
Gui,2: Show, x%x% y%y% w%w%  h%h% 
;----------
Gui,2:+Parent%AId%                        ;- <<<<<<<< PARENT
Gui,3:destroy                             ;- <<<<<<<< DESTROY
Guicontrol,1:disable,A2
Guicontrol,1:enable,A1
Guicontrol,1:enable,A3
return
;--------------------------------
Remove2:
vlcx.playlist.items.clear()
vlcx.playlist.stop()
Guicontrol,1:disable,A1
Guicontrol,1:enable ,A2
Guicontrol,1:enable ,A3
Gui,2:destroy
Gui,1:default
return
;======================================================
;============ 3th =====================================
Add3:
Gui,1:submit,nohide
Gui,3: default
;Gui,3: -DPIScale -Caption +Parent2 alwaysontop
Gui,3: -DPIScale +HwndCId  -Caption -Border +alwaysontop     ;-- < C
;---------
SS_REALSIZECONTROL := 0x40
Gui,3: Color,Black,Black                 
HK3=Esc
  Hotkey,%hk3%,Remove3,ON
;---------
x:=(wa*0.1)/xx,y:=(ha*.1)/xx,w:=(wa*58)/xx,h:=(ha*54)/xx
;Gui,3:Add,picture, x%x% y%y% w%w%  h%h% ,C:\windows\web\wallpaper\windows\img0.jpg
Gui,3:Add,picture, x%x% y%y% w%w%  h%h% ,C:\windows\web\screen\img100.jpg
;---------
x:=(wa*1)/xx,y:=(ha*1)/xx,w:=(wa*6)/xx,h:=(ha*2.3)/xx
Gui,3: Add, Button, x%x% y%y% w%w%  h%h%   gS3, Some -3
y:=(ha*4)/xx
Gui,3: Add, Button, x%x% y%y% w%w%  h%h%   gO3, Other-3
;----------
x:=(wa*6)/xx,y:=(ha*.1)/xx,w:=(wa*58)/xx,h:=(ha*56)/xx
Gui,3: Show, x%x% y%y% w%w%  h%h% 
;----------
Gui,3:+Parent%AId%                           ;- <<<<<<<<< PARENT
Gui,2:destroy                                ;- <<<<<<<<< destroy
Guicontrol,1:enable,A1
Guicontrol,1:enable,A2
Guicontrol,1:disable,A3
return
;-------------------------------------
Remove3:
Guicontrol,1:disable,A1
Guicontrol,1:enable ,A2
Guicontrol,1:enable ,A3
Gui,3:destroy
Gui,1:default
return
;-------------------------------------
S3:
msgbox,SOME-3
return
O3:
msgbox,OTHER-3
return
;================== END SCRIPT ====================================

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Can't interact with controls of a Child GUI

Post by malcev » 18 Aug 2022, 06:12

So basically it isn't a true child window
If You need true child window then You can try like this.
But there will be some issues.

Code: Select all

#NoEnv
#SingleInstance, Force
OnMessage(WM_LBUTTONDOWN := 0x201, "WM_LBUTTONDOWN")

GUI, Main:New, +Resize +HWNDparentID
GUI, Add, Text, , AHK Version - %A_Ahkversion%
GUI, Color, B0B0B0
GUI, Main:Show, w600 h400, Main


GUI, Child:New, +ParentMain
GUI, Add, Edit, , Can you edit me?
GUI, Add, Edit, , How about me?
GUI, Child:Show, w200, Child
Return

MainGUIClose:
ExitApp


WM_LBUTTONDOWN()
{
   Mousegetpos,,,, ControlUnderMouse
   if InStr(ControlUnderMouse, "edit")
   {
      GuiControlGet, FocusedControl, Focus
      if (FocusedControl != ControlUnderMouse)
         GuiControl, Focus, % ControlUnderMouse
   }
}
But if You need to add window of another process to Your gui as child window, then You can catch mouse clicking event like this:

Code: Select all

~LButton::
Mousegetpos,,, WindowUnderMouse, ControlUnderMouse
if (WindowUnderMouse = parentID) and InStr(ControlUnderMouse, "edit")
{
   ControlGetFocus, FocusedControl, % "ahk_id " parentID
   if (FocusedControl != ControlUnderMouse)
      ControlFocus, % ControlUnderMouse, % "ahk_id " parentID
}
return

Post Reply

Return to “Ask for Help (v1)”