AutoHotkey Community

It is currently May 27th, 2012, 12:57 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: September 24th, 2011, 3:51 am 
Offline

Joined: November 1st, 2006, 8:33 pm
Posts: 21
Location: Chicago, IL
Insight needed. Is the "Gui, New" command now required if using named GUI's? The documentation suggests it is needed to insure "Gui, Add" statements work correctly. Does it provide any other benefit?

Can someone provide a simple code example showing the creation of a named GUI window using this command?

Thanks,
TL


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 24th, 2011, 4:37 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Code:
Gui, MyGui: +ToolWindow +Resize +LabelGui
Gui, MyGui: Show, y200 w200 h50, MyGui

Gui, NewGui: New, ToolWindow Resize LabelGui, NewGui ; <- name GUI before using Show
Gui, NewGui: Show, y300 w200 h50
return

GuiClose:
ExitApp


"Gui, New" isn't really required for most cases. However, it does allow you to make unnamed GUIs (which is different than the Default GUI functionality, which is "GUI, 1" to begin with). This allows you to create GUIs - for instance in a function - that won't use up the GUI Namespace. You can reference them by their HWND:
Code:
Gui, New, HWNDh1 LabelGui, GUI #1
Gui, New, HWNDh2 LabelGui, GUI #2
Gui, %h1%: Show, y200 w200 h50
Gui, %h2%: Show, y300 w200 h50
return

GuiClose:
ExitApp

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
PostPosted: September 24th, 2011, 8:38 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
TL wrote:
Is the "Gui, New" command now required if using named GUI's?
Not at all.
Quote:
The documentation suggests it is needed to insure "Gui, Add" statements work correctly.
I suppose you're referring to this:
Quote:
Note that if this command is not used, simply using one of the other Gui sub-commands such as Gui, Add may cause a GUI to be created.

I think you misunderstood. The intent of that statement was to make it clear that Gui New is not mandatory: you can just use Gui Add, and the GUI will be created automatically.
Quote:
Does it provide any other benefit?
One common error when creating a GUI inside a hotkey subroutine is assuming that the GUI didn't already exist, even though it wasn't destroyed since the last time the hotkey was pressed. Typically the end result is an error message saying that a Gui control variable is already in use. If you always begin with Gui Name: New, this won't be a problem - the old GUI will be destroyed automatically.

Some users thought that setting the title when creating the Gui was more logical than doing it with Gui Show. Gui New allows this.

However, the main purpose of Gui New is to create an unnamed GUI, as jethrow demonstrated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 24th, 2011, 2:31 pm 
Offline

Joined: November 1st, 2006, 8:33 pm
Posts: 21
Location: Chicago, IL
Thanks jethrow and Lexikos. A concise, clear, complete, and quick response. Very much appreciated.

Lexikos, and everyone who helped, thanks for all of the new AHK functionality. As a programmer (aren't we all), I can appreciate the talent and time applied to this project.

TL


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, chaosad, Google Feedfetcher, MSN [Bot] and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group