[Solved] Gui, New

Report problems with documented functionality
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

[Solved] Gui, New

30 Jul 2014, 10:54

I assume this is a bug.
AHK 1.1.15.00
Win7 64bit

Without the Gui,New command, the script works as expected.

Code: Select all

Gui, New  ;<<< with this command, F3 doesn't show the gui after closed.
Gui, Add, Button, gButton,  %A_AHKVersion%
Gui, Show, , 
Return
                
Button:
    Gui, Submit, 
return

F3::
    Gui, Show,  
return

Esc::
 ExitApp
Return
Last edited by toralf on 30 Jul 2014, 11:09, edited 1 time in total.
ciao
toralf
User avatar
fincs
Posts: 527
Joined: 30 Sep 2013, 14:17
Location: Seville, Spain
Contact:

Re: [Bug] Gui, New

30 Jul 2014, 10:57

Not a bug. Gui, New creates a new anonymous Gui and sets it as default for the current thread only. Other threads (not generated by it) cannot refer to it in any way other than by HWND (or by doing Gui %Hwnd%:Default).
fincs
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 - [My project list]
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: [Bug] Gui, New

30 Jul 2014, 11:08

Thank you for the explanation.

I didn't know about the anonymity of the GUI, I assumed since it was in the AutoExec Section it would be global...
Don't know if it would be worthwhile to add your comment to the docs.

The 1.1.15.00 doc state
Creates a new window.
For convenience, the new window is set as the default for the current thread.
Maybe clearer would be
Creates a new anonymous Gui
For convenience, the new window is set as the default for the current thread only. Other threads (not generated by the Gui) cannot refer to it in any way other than by HWND (or by doing Gui %Hwnd%:Default).

this works:

Code: Select all

Gui, New, +HwndhGui
Gui, Add, Button, gButton,  %A_AHKVersion%
Gui, Show, , 
Return
                
Button:
    Gui, Submit, 
return

F3::
    Gui, %hGui%:Show,  
return

Esc::
 ExitApp
Return
ciao
toralf
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: [Solved] Gui, New

30 Jul 2014, 12:12

or change the docs to describe when and why you would use Gui, New if at all

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: [Bug] Gui, New

01 Aug 2014, 05:39

Notice the first line of code.
Creates a new window.

Code: Select all

Gui, New  ; Creates a new unnamed GUI.
Gui, Name:New  ; Creates a new GUI, destroying any existing GUI with that name.
Gui New does not create an anonymous Gui - obviously - if you name the Gui.

Changing the default Gui does not affect other threads if you do it explicitly, so there's no reason to expect it would if the Gui New command does it.

I suppose a reference to the statement "Non-GUI threads use 1 as their default." (found elsewhere) would help.

guest3456: perhaps.
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: [Solved] Gui, New

01 Aug 2014, 08:10

I ended up giving Gui New a comprehensive review.

Btw,
toralf wrote:I assumed since it was in the AutoExec Section it would be global...
Regardless of how you do it, changing the default GUI in the auto-execute section does not affect other threads. This is why the documentation says "Non-GUI threads use 1 as their default." and not "unless overridden". Perhaps the reason for it is that unlike most thread-specific settings, the default GUI depends on how the thread was launched.
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: [Solved] Gui, New

01 Aug 2014, 12:15

Thank you lexikos,

With your explanation and the doc update it is more clear.

My problem was, that I assumed that even if GUI,New would create a unnamed GUI the GUI would still have a number. Since in my example no other GUI existed, I assumed it would default to 1. Thus that not thread command would still work with that GUI.
So to clearly state this it would be great if you could slightly tweak the example comment in the doc a second time:
; creates an unnamed and unnumbered GUI
ciao
toralf
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: [Solved] Gui, New

01 Aug 2014, 15:00

lexikos wrote:I ended up giving Gui New a comprehensive review.
excellent work, it clarifies everything for me

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: [Solved] Gui, New

01 Aug 2014, 19:48

toralf wrote:My problem was, that I assumed that even if GUI,New would create a unnamed GUI the GUI would still have a number.
I'll add "and unnumbered" somewhere. Currently a GUI number is internally just a name, and is also used in exactly the same way, though numbers outside the range 1..99 are assumed to be HWNDs.

Looking at it another way, unnamed GUIs are numbered, but the number is generated automatically by the OS. You use the HWND in the same way that you use 1..99, and it is even returned by A_Gui in place of a name or number. The only difference is that if you make a number 1..99 the default and then destroy the GUI, that number remains the default, whereas if the GUI has only a HWND, the HWND becomes invalid and so the default reverts to 1.
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: [Solved] Gui, New

01 Aug 2014, 20:36

Thanks, appreciated
ciao
toralf

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 45 guests