| View previous topic :: View next topic |
| Author |
Message |
biatche
Joined: 23 Feb 2008 Posts: 59
|
Posted: Sun Apr 27, 2008 3:00 pm Post subject: [Help] How do I prevent duplicate Gui's? |
|
|
Say I have a Menu Tray item that calls a gui window
| Code: |
menu, tray, add, item, opengui
opengui:
gui blabalbala
|
problem here is, if i click "item" that opens the gui window... and without closing that, i click "item" again... ill get some error.
now i can see only two solutions to that
first, opening twice would only send focus to the same gui window
second, i make the tray menu unclickable
if someone can show me how to do those ways, i'd appreciate it, but if there's a better and more efficient method around it, i'd love to know too thanks[/code] |
|
| Back to top |
|
 |
SomeGuy
Joined: 21 Apr 2008 Posts: 96 Location: somewhere
|
Posted: Sun Apr 27, 2008 3:05 pm Post subject: |
|
|
| Code: | menu, tray, add, item, opengui
opengui:
If !hGui {
Gui, +LastFound
gui blabalbala
;// the other gui stuff for a new gui
hGui := WinExist()
}else{
WinShow, ahk_id %hGui%
}
;//the rest of your code
;//or whatever else floats your boat
|
|
|
| Back to top |
|
 |
biatche
Joined: 23 Feb 2008 Posts: 59
|
Posted: Sun Apr 27, 2008 3:37 pm Post subject: |
|
|
| Code: | LicensePage:
If !hGui
{
Gui,1: +LastFound
hGui := WinExist()
msgbox, hi
}
else
{
WinShow, ahk_id %hGui%
msgbox, bye
}
Gui 1:+LabelLicenseGui
Gui, 1:commandsblablaba ;rest of code
|
do you see anything wrong above? when i first click item, i get a hi msg box, everytime after that i get a bye.. until i restart the script |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
Posted: Sun Apr 27, 2008 11:05 pm Post subject: |
|
|
because hGui is defined, it will always go to the bye section. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
biatche
Joined: 23 Feb 2008 Posts: 59
|
Posted: Mon Apr 28, 2008 1:51 am Post subject: |
|
|
| someone mind explaining to me what hGui is ? |
|
| Back to top |
|
 |
biatche
Joined: 23 Feb 2008 Posts: 59
|
Posted: Mon Apr 28, 2008 2:14 am Post subject: |
|
|
im still new at this, i assume hGui is just a variable like any other..
and so i suppose the flaw has to do with hGui := WinExist() as when gui is destroyed, that variables remains unchanged....
ill try to figure something out, in the mean time, if anyone can tell me how to handle it, i'd appreciate it |
|
| Back to top |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 970 Location: London, UK
|
Posted: Mon Apr 28, 2008 2:29 am Post subject: |
|
|
That is correct.
| Code: | LicensePage:
Gui,1: +LastFound
If !hGui := WinExist()
{
; The gui needs to be created here.
msgbox, hi
}
else
{
WinShow, ahk_id %hGui%
msgbox, bye
}
Gui 1:+LabelLicenseGui
Gui, 1:commandsblablaba ;rest of code |
_________________ Steve F AKA Superfraggle
http://r.yuwie.com/superfraggle |
|
| Back to top |
|
 |
Z Gecko Guest
|
Posted: Mon Apr 28, 2008 2:50 am Post subject: |
|
|
the basic problem is imho,
that you use a wrong approach to the whole thing.
i suggest two other methods:
1. create the gui only once,
and use Gui, Show and Gui, Submit or Hide
to Show or hide your Gui. (this is the most common way)
2. simply use Gui, Destroy prior to the Gui-creation part of your script. |
|
| Back to top |
|
 |
biatche
Joined: 23 Feb 2008 Posts: 59
|
Posted: Mon Apr 28, 2008 3:50 am Post subject: |
|
|
thanks for advice with show/hide... although my approach is wrong, ive solved it by using gui +LastFoundExist
but anyway, im a bit lazy to change all that code now, but in future ill be sure to use that hide
thanks all |
|
| Back to top |
|
 |
|