Gui,New; is the handle of Gui window the name of Gui window?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Gui,New; is the handle of Gui window the name of Gui window?

Post by trismarck » 21 Aug 2014, 16:45

This is really nitpicking, but anyway:
Gui, New wrote:If the GUI which launched the current thread was created this way, A_Gui contains a HWND instead of a name.
The way I interpret this sentence is that the HWND (the _handle_) of the Gui window is _not_ a name of the Gui window. Note that the sentence does _not_ describe the case where the Gui window has _both_ 'the name' and the handle; in that context, the sentence would be correct I guess. Or perhaps, 'instead of a name' could be read that if the name is an empty string, then A_Gui contains HWND?

Also:
Gui, New wrote:If a name is specified, any existing GUI with that name is destroyed.

Code: Select all

DetectHiddenWindows, On
Gui, new, hwndh1
MsgBox % WinExist("ahk_id" h1) > 0	; 1
gui, %h1%:new
MsgBox % WinExist("ahk_id" h1) > 0	; 0
Instead of using the name of the Gui window, a handle was specified and Gui, New has still destroyed the window.

Another thing is this:
A_Gui wrote:The name or number of the GUI that launched the current thread. This variable is blank unless a Gui control, menu bar item, or event such as GuiClose/GuiEscape launched the current thread.
So A_Gui can't contain the handle of the Gui window, because the handle is not the name, which seems contradictory with:
... A_Gui contains a HWND instead of a name.

User avatar
joedf
Posts: 7895
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Gui,New; is the handle of Gui window the name of Gui win

Post by joedf » 21 Aug 2014, 18:54

Interesting... Should this go into the doc Suggestions thread?

lexikos
Posts: 7187
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Gui,New; is the handle of Gui window the name of Gui win

Post by lexikos » 21 Aug 2014, 22:38

No, the HWND is not the name. If it was, the Gui would not be unnamed, as the documentation refers to it.

trismarck, I cannot find the sentence you quoted in the documentation you linked to, though I know it existed at some point. Perhaps you are referring to old documentation (cached by your browser?).
Or perhaps, 'instead of a name' could be read that if the name is an empty string,
Who says its an empty string? Perhaps it's NULL, or just not stored at all. The important point is that the Gui has no name. I will add a note to A_Gui.
Instead of using the name of the Gui window, a handle was specified and Gui, New has still destroyed the window.
This usage could be considered invalid. The documentation only shows Gui, New and Gui, Name:New. The documentation often does not say what happens when you pass a command invalid parameters.

joedf: trismarck "nitpicked" and asked about interpretation, but did not make suggestions.

User avatar
joedf
Posts: 7895
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Gui,New; is the handle of Gui window the name of Gui win

Post by joedf » 22 Aug 2014, 01:03

@Lexikos Oh ok, I see

just me
Posts: 7747
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Gui,New; is the handle of Gui window the name of Gui win

Post by just me » 22 Aug 2014, 01:33

Let's say: A GUI handle is not the GUI name but can be used instead of that and will behave like a name then.

User avatar
evilC
Posts: 4791
Joined: 27 Feb 2014, 12:30

Re: Gui,New; is the handle of Gui window the name of Gui win

Post by evilC » 22 Aug 2014, 10:03

Are you querying exactly what an HWND is?

The HWND is a OS (ie Windows) assigned ID for each window.
Because it is assigned by the OS, it is very useful for DLL calls and other ways of interacting with the OS (eg OnMessage)

For example:

Get the HWND of the parent (ie a control will return the GUI's HWND)

Code: Select all

	GetParent(hwnd){
		return DllCall("GetParent", "Ptr", hwnd)
	}
Get the size of the client rect (internal area) of a GUI:

Code: Select all

	GetClientRect(hwnd){
		VarSetCapacity(rect, 16, 0)
        DllCall("GetClientRect", "Ptr", hwnd, "Ptr", &rect)
        return {l: NumGet(rect, 0, "Int"), t: NumGet(rect, 4, "Int") , r: NumGet(rect, 8, "Int"), b: NumGet(rect, 12, "Int")}
	}
The downside is that the HWND for a given window is not static and will vary on each run of the code.
A small price to pay for the power it gives you IMHO.

guest3456
Posts: 3162
Joined: 09 Oct 2013, 10:31

Re: Gui,New; is the handle of Gui window the name of Gui win

Post by guest3456 » 22 Aug 2014, 11:02

lol of course he knows what a hwnd is


User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: Gui,New; is the handle of Gui window the name of Gui win

Post by trismarck » 23 Aug 2014, 10:11

[url=http://ahkscript.org/boards/viewtopic.php?p=24267#p24267]Lexikos[/url]/Gui, New wrote:Gui, New ; Creates a new unnamed and unnumbered GUI.
Right, so now: is the number of the gui window the name of the gui window?
It seems that the gui window may only have one of the following:
  • a numeric name
  • a non-numeric name
  • be unnamed
And a handle in addition to all of this.
But this does not explain of whether the name of the gui window can be a number or not.
Lexikos wrote:No, the HWND is not the name. If it was, the Gui would not be unnamed, as the documentation refers to it.
Ok, unnamed:
Creating Multiple GUI Windows wrote:[v1.1.04+]: Any number of _unnamed_ GUI windows can be created using Gui, New.
Lexikos wrote:trismarck, I cannot find the sentence you quoted in the documentation you linked to, though I know it existed at some point. Perhaps you are referring to old documentation (cached by your browser?).
What I've done was I copied the documentation from the offline help file which was of version 1.1.15.02 and then got the links to the relevant parts of the documentation from the online help. The revision of Gui, New was introduced at 1.1.15.03. Sorry about that.
Lexikos wrote:
Or perhaps, 'instead of a name' could be read that if the name is an empty string,
Who says its an empty string? Perhaps it's NULL, or just not stored at all. The important point is that the Gui has no name.
So I should have said: 'unspecified' instead of 'an empty string'. Thanks.
Lexikos wrote:The documentation only shows Gui, New and Gui, Name:New. The documentation often does not say what happens when you pass a command invalid parameters.
It was interesting to realize just now that, although Gui is a fairly complicated command, it doesn't set errorlevel; it only throws exceptions at run-time. But this is probably because the errors are detected at _compile_-time:

Code: Select all

Gui, xyz
; ==> Parameter #1 invalid.
;      Specifically: xyz
Guest3456: actually (;, I haven't yet understood what a handle really is yet. HWND is certainly a number of A_PtrSize size, but the void thing still remains a void. This seems to be good candidate for another topic, if ever.

EvilC (nitpick did you know):
Spoiler

User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: Gui,New; is the handle of Gui window the name of Gui win

Post by trismarck » 25 Aug 2014, 08:49

Gui, GuiName:Default - if handle is not name, GuiName looks incorrect. If it was correct, then that would mean that if the AHK script comprises solely out of unnamed windows, there is no way of changing the current default gui window to some previously created unnamed gui window w/o destroying that previous window first (~Gui, New), as Gui, Default can only work with window names, not handles.

//edit: actually, I could, by spawning a separate thread, but that's not the point.
Last edited by trismarck on 25 Aug 2014, 09:51, edited 1 time in total.

Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: Gui,New; is the handle of Gui window the name of Gui win

Post by Coco » 25 Aug 2014, 09:25

trismarck wrote:there is no way of changing the current default gui window to some previously created unnamed gui window w/o destroying that previous window first (~Gui, New)
When using Gui, New w/o specifying a GuiName, it's always best practice to store a reference to that newly created Gui:

Code: Select all

Gui New, +LastFound
hMainWindow := WinExist()
; OR
Gui New, +HwndhMainWindow
trismarck wrote:, as Gui, Default can only work with window names, not handles
You can use GUI handles:

Code: Select all

Gui New, +HwndhMainWindow
Gui New, +HwndhSubWindow
Gui Add, Button, h30, SubWindow button
Gui %hMainWindow%:Default
Gui Add, Button, h30, MainWindow button
Gui Show, w300, Main Window
Gui %hSubWindow%:Default
Gui Show, w300, Sub Window
return
GuiClose:
ExitApp

User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: Gui,New; is the handle of Gui window the name of Gui win

Post by trismarck » 25 Aug 2014, 10:06

Coco, I get your point, I'ma just sayin that

Code: Select all

Gui %hMainWindow%:Default
it's not documented for Gui, Default to work with _handles_ (vs names). I mean, it works, but what if at some point it cuts one of my fingers when I run it.

Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: Gui,New; is the handle of Gui window the name of Gui win

Post by Coco » 25 Aug 2014, 10:11

Oic, my bad, didn't read the entire thread. :-P. I believe it's because the usage of Gui handles was implemented later and that part of the documentation might have been overlooked.

Post Reply

Return to “Ask For Help”