AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Gui problem

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Tue Jun 20, 2006 2:28 pm    Post subject: Gui problem Reply with quote

I use this kind of setup

Code:


Editor_Init()
return

;----------------------------------------------------------

Editor_Init()

{
  global

  Editor_GUI = 5
  Editor_Create()
}

;----------------------------------------------------------

Editor_Create()
{
    Gui, %editor_GUI%:Add, Text, x340 y522 w20 h20, >> 
    Gui, %editor_GUI%:Add, Text, x340 y572 w20 h20, >>

    Gui,%editor_GUI%:Show, h644 w362, Editor
}



How can I achive to have the line:

Code:

%editor_Gui%GuiClose:
  ; some code here
return

_________________
Back to top
View user's profile Send private message MSN Messenger
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Tue Jun 20, 2006 3:19 pm    Post subject: Reply with quote

You can't, labels cannot be defined at run time.
If the set of possible numbers is limited, define a label for each of them...
Or perhaps by using OnMessage with WM_CLOSE.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Roland



Joined: 08 Jun 2006
Posts: 244

PostPosted: Tue Jun 20, 2006 3:23 pm    Post subject: Reply with quote

Well... not really what you wanted, I know, but I think it works:

Code:
Editor_Init()
return

;----------------------------------------------------------

Editor_Init()

{
  global

  Editor_GUI = 5
  Editor_Create(Editor_GUI)
}

;----------------------------------------------------------

Editor_Create(editor_GUI)
{
    Gui, %editor_GUI%:Add, Text, x340 y522 w20 h20, >> 
    Gui, %editor_GUI%:Add, Text, x340 y572 w20 h20, >>

    Gui,%editor_GUI%:Show, h644 w362, Editor
}

GuiClose:
2GuiClose:
3GuiClose:
4GuiClose:
5GuiClose:
6GuiClose:
7GuiClose:
8GuiClose:
9GuiClose:
10GuiClose:
11GuiClose:
12GuiClose:
13GuiClose:
14GuiClose:
15GuiClose:
16GuiClose:
17GuiClose:
18GuiClose:
19GuiClose:
20GuiClose:
21GuiClose:
22GuiClose:
23GuiClose:
24GuiClose:
25GuiClose:
26GuiClose:
27GuiClose:
28GuiClose:
29GuiClose:
30GuiClose:
31GuiClose:
32GuiClose:
33GuiClose:
34GuiClose:
35GuiClose:
36GuiClose:
37GuiClose:
38GuiClose:
39GuiClose:
40GuiClose:
41GuiClose:
42GuiClose:
43GuiClose:
44GuiClose:
45GuiClose:
46GuiClose:
47GuiClose:
48GuiClose:
49GuiClose:
50GuiClose:
51GuiClose:
52GuiClose:
53GuiClose:
54GuiClose:
55GuiClose:
56GuiClose:
57GuiClose:
58GuiClose:
59GuiClose:
60GuiClose:
61GuiClose:
62GuiClose:
63GuiClose:
64GuiClose:
65GuiClose:
66GuiClose:
67GuiClose:
68GuiClose:
69GuiClose:
70GuiClose:
71GuiClose:
72GuiClose:
73GuiClose:
74GuiClose:
75GuiClose:
76GuiClose:
77GuiClose:
78GuiClose:
79GuiClose:
80GuiClose:
81GuiClose:
82GuiClose:
83GuiClose:
84GuiClose:
85GuiClose:
86GuiClose:
87GuiClose:
88GuiClose:
89GuiClose:
90GuiClose:
91GuiClose:
92GuiClose:
93GuiClose:
94GuiClose:
95GuiClose:
96GuiClose:
97GuiClose:
98GuiClose:
99GuiClose:
If a_gui = %Editor_GUI%
   Gosub, EditorGuiClose
return

EditorGuiClose:
Msgbox Some code here.
return


Rolling Eyes
Back to top
View user's profile Send private message
evl



Joined: 24 Aug 2005
Posts: 1238

PostPosted: Tue Jun 20, 2006 5:14 pm    Post subject: Reply with quote

... and with "GuiEscape:" too it would really turn into a big script Laughing
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Tue Jun 20, 2006 7:20 pm    Post subject: Reply with quote

Roland, that was really funny Smile

I know about WM_CLOSE message, I wondered if there is some alternative.

Is it possible to cheat AHK by creating dynamic label via HotKey command, and use it for GUI, I wonder...


Wish (Chris, read this):
GUIs to have names ?

I don't know how U got the idea for numbers in the first sense ? Is it some compatibility isue maybe ?
_________________
Back to top
View user's profile Send private message MSN Messenger
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Wed Jun 21, 2006 8:49 am    Post subject: Reply with quote

majkinetor wrote:
Wish (Chris, read this):
GUIs to have names ?

I don't know how U got the idea for numbers in the first sense ? Is it some compatibility isue maybe ?
I guess no, AFAIK, Chris made this GUI stuff from scratch. I would say he chose this for sake of simplicitiy.
This GUI stuff wasn't probably designed to make full applications (althought it is flexible enough to allow it, now), rather to make some dialogs with a limited number of windows. But users always go beyond your expectations...

As for naming GUIs, it is already possible. Recycling jballi's code:
Code:
mainGUI = 1
slaveGUI = 2

;-- 1st GUI
Gui %mainGUI%:Add, Edit,r20 w450
Gui %mainGUI%:Show, AutoSize, GUI-1

;-- 2nd GUI
Gui %mainGUI%:+Disabled
Gui %slaveGUI%:+Owner%mainGUI%
Gui %slaveGUI%:Add, Edit, r1 w200
Gui %slaveGUI%:Show, AutoSize, GUI-2
Return

GuiClose:
ExitApp

2GuiClose:
Gui %mainGUI%:-Disabled
Gui %slaveGUI%:Destroy
Return
But we still have the issue of hard-coded labels.
Perhaps a way to manage this (lot of GUIs) is to add a Gui command:

Gui %guiID%:OnClose, ColorfulLabelName%evenWithDynamicPart%!
and of course, OnEscape, OnSize, OnContextMenu, OnDropFiles...
Or use one common sub-command and a modifier to specify which event.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Wed Jun 21, 2006 11:56 am    Post subject: Reply with quote

Quote:
Recycling jballi's code:

It is the same as I did.

Quote:
Perhaps a way to manage this (lot of GUIs) is to add a Gui command:

I find this to be nice solution. You can have keywords for all supported events, and even some new can be added:

Gui %guiID%:OnClose
Gui %guiID%:OnKeyUp
Gui %guiID%:OnHide
Gui %guiID%:OnShow ;a must
Gui %guiID%:OnActivate
...

Much better then adding dynamic labels.
I consider this to be high priority task. I don't know what Chris did surmise when designing this, but the fact that script often doesn't create intensive GUIs isn't enough for this choice, for you may have 20 scripts eatch creating its own little GUI. Without this, it is impossible to import them all into single script without some script initialisation parameter that will pass starting gui number to scripts init function witch should return how many Guis script used.

Code:

-- Autohotkey.ini---

   g :=  Launcher_Init(0)
   g += Favorites_Init(g)
   g += GuiScript_Init(g)

return

; --- includes ---
#include Launcher
#Include Favorites
#Include GuiScript


Then scripts can do something like

Code:

Launcher_init(lastGui)
{
    myGui1 := lastGui + 1
    myGui2 := lastGui + 2
 

;   GUI %myGui1%:OnClose fGui1_OnClose
;   GUI %myGui1%:OnShow fGui1_OnShow
    GUI %myGui1%:Add ...
    ...

    GUI %myGui2%:Add ...
    ....

    return 2
}


This will do even now, even without labels since the one can use OnMessage(WM_SHOW...) but it is very stupid to do so, if you can just add Gui names. So, you can forget about gui numbers and just use unique names for your Guis. Together with your addon about new event commands this will make scrpts GUI independent, witch is very important.
_________________
Back to top
View user's profile Send private message MSN Messenger
foom



Joined: 19 Apr 2006
Posts: 386

PostPosted: Wed Jun 21, 2006 1:07 pm    Post subject: Reply with quote

Launching a global label (if it exists) would be sufficient enough to handle multiple guis effectively and i think easier to implement for Chris.

Code:
*GuiSize:
msgbox, Gui:%a_gui% has been resized
return
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Wed Jun 21, 2006 2:00 pm    Post subject: Reply with quote

will not do

Imagine script1 use *GuiSize for Gui1 Gui2, and script2 use *GuiSize for its Gui3 Gui4. If you import those scripts, you will get two labels on different positions. Chirs may implement label merge but I don't like the idea to have different scripts in one sublabel:

Code:

*GuiClose:

;from script 1
if (a_gui = gui1) ...
if (a_gui = gui2) ...

;from script 2
if (a_gui = gui3) ...
if (a_gui = gui4) ...

return


so if I accedently use already used gui number instead of error some other routine may be executed... ugly if you ask me.
_________________
Back to top
View user's profile Send private message MSN Messenger
foom



Joined: 19 Apr 2006
Posts: 386

PostPosted: Wed Jun 21, 2006 2:17 pm    Post subject: Reply with quote

/me just wonders who else would benefit from it.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Wed Jun 21, 2006 2:49 pm    Post subject: Reply with quote

majkinetor wrote:
You can have keywords for all supported events, and even some new can be added:

Gui %guiID%:OnClose
Gui %guiID%:OnKeyUp
Gui %guiID%:OnHide
Gui %guiID%:OnShow ;a must
Gui %guiID%:OnActivate
This has been suggested several times and is planned (though I don't know when). I'll add your example to my notes for later review.

Quote:
I consider this to be high priority task. I don't know what Chris did surmise when designing this...
It was designed that way because simplicity seemed to outweigh flexibility in this case. For example, it's my belief that around 80% of all GUI scripts use only a single GUI window. For them, the existing mechanism seems optimal in terms of simplicity and readability. Of the remaining 20% of GUI scripts, I suspect that about 80% of them use only two GUI windows. If true, that leaves only about 4% of GUI scripts that use more than 2 windows. Assuming this is close to accurate, cost/benefit analysis seems to favor an approach that maximizes ease-of-use for scripts containing 1 or 2 windows.

Quote:
Together with your addon about new event commands this will make scrpts GUI independent, witch is very important.
I see the benefit of having dynamically-numbered or named GUIs (e.g. to faciliate script merging), so I'll add this to the to-do list.

Thanks.
Back to top
View user's profile Send private message Send e-mail
skrommel



Joined: 30 Jul 2004
Posts: 178

PostPosted: Sun Mar 09, 2008 2:16 am    Post subject: Reply with quote

Very Happy Any changes in getting "global" window events?
When handling tens or hundreds of guis, I have to have a window event for every gui:

1GuiClose:
2GuiClose:
3GuiClose:
...
99GuiClose:

Would it be possible to make a "global" window event, to make the code below work? Or is there an OnMessage I can catch?

Skrommel


Code:

; Press F1 to create guis, close them to display a message.
; Only the first window is caught

counter=0

F1::
counter+=1
Gui,%counter%:Show,w100 h100
Return

GuiClose:
MsgBox,Closing %A_Gui%
Gui,%A_Gui%:Destroy
Return

_________________
www.1HourSoftware.com
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Sun Mar 09, 2008 3:19 am    Post subject: Reply with quote

skrommel wrote:
Very Happy Any changes in getting "global" window events?

...yes, when this topic was created it didn't exist, but you can now use Gui, +Label...

Code:
Gui, 19:+Default
Gui, +LabelExample_Gui
Gui, Show
return

Example_GuiClose:
ExitApp

...untested, but this should work too...

Code:
Loop, 99 {
   i:=A_Index
   Gui, %i%:+Default
   Gui, +LabelAllGui
   Gui, Show, , Gui(%i%)
}
return

AllGuiEscape:
AllGuiClose:
ExitApp

Find all posts by skrommel wrote:
Posted: Sat, Mar 8, 2008 --- 3/8/08 8:16:19pm Subject: Gui problem
Posted: Thu, Jun 21, 2007 --- 6/21/07 9:07:19pm Subject: Only your own

...was that blackhole fun?
Back to top
skrommel



Joined: 30 Jul 2004
Posts: 178

PostPosted: Sun Mar 16, 2008 9:46 am    Post subject: Reply with quote

Very Happy Wonderful! Thank you, there's nothing like reading the manual!

Skrommel
_________________
www.1HourSoftware.com
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group