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 

[Help] How do I prevent duplicate Gui's?

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



Joined: 23 Feb 2008
Posts: 59

PostPosted: Sun Apr 27, 2008 3:00 pm    Post subject: [Help] How do I prevent duplicate Gui's? Reply with quote

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 Smile thanks[/code]
Back to top
View user's profile Send private message
SomeGuy



Joined: 21 Apr 2008
Posts: 96
Location: somewhere

PostPosted: Sun Apr 27, 2008 3:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
biatche



Joined: 23 Feb 2008
Posts: 59

PostPosted: Sun Apr 27, 2008 3:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Sun Apr 27, 2008 11:05 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
biatche



Joined: 23 Feb 2008
Posts: 59

PostPosted: Mon Apr 28, 2008 1:51 am    Post subject: Reply with quote

someone mind explaining to me what hGui is ?
Back to top
View user's profile Send private message
biatche



Joined: 23 Feb 2008
Posts: 59

PostPosted: Mon Apr 28, 2008 2:14 am    Post subject: Reply with quote

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
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 970
Location: London, UK

PostPosted: Mon Apr 28, 2008 2:29 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Z Gecko
Guest





PostPosted: Mon Apr 28, 2008 2:50 am    Post subject: Reply with quote

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

PostPosted: Mon Apr 28, 2008 3:50 am    Post subject: Reply with quote

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
View user's profile Send private message
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