Sign in to follow this  
Followers 0

Problems with GuiMsg

14 posts in this topic

Posted (edited)

I've problems with closing my gui with the red X:

GuiCreate("Titel")
...
GuiWaitClose()

If GuiRead() = $butMove then ...
If GuiRead() = $butCopy then ...
If GuiRead() = $butConfig Then ...
If GuiRead() = $butCancel OR GuiMsg(0) = -3 Then Exit

With the build before 10th June this worked fine. Now it doesn't. If I change the code to "GuiMsg() = -3" (without the 0) it works, but I have to click twice on the X (or once on the X and once on any other button. Am I doing something wrong or is this a bug?

Edit: Now I've noticed that with "GuiMsg() = -3" all other buttons doesn't work anymore. They are all closing the gui, but only after 2 clicks. Maybe I must solve this with If...ElseIf...Else...EndIf.

Closing a gui when not using GuiWaitClose() is no problem. Strange...

Edited by peterbonge

Share this post


Link to post
Share on other sites



Posted (edited)

Talking about closing Guis...

When I click on a button the Gui hides itself and the specified function runs.

I use this workaround:

GUIShow()
            AddCat();user defined function

And the Gui window returns like it was before.

Edited by SlimShady

Share this post


Link to post
Share on other sites

Posted (edited)

Hmmm...I'm using the 10th build and have no problem.

I used this:

GuiCreate("Titel")
$butMove = GuiSetControl("button","Move",50,10,70,22)
$butCopy = GuiSetControl("button","Copy",50,40,70,22)
$butConfig = GuiSetControl("button","Config",50,70,70,22)
$butCancel = GuiSetControl("button","Cancel",50,100,70,22)
GuiWaitClose()

If GuiRead() = $butMove then Msgbox(0,"","Move clicked")
If GuiRead() = $butCopy then Msgbox(0,"","Copy clicked")
If GuiRead() = $butConfig Then Msgbox(0,"","Config clicked")
If GuiRead() = $butCancel OR GuiMsg(0) = -3 Then Exit

I'm using WinXPSP1 and all works fine :D

Edit: what happens if you use the example from the help file?:

#include "GUIConstants.au3"
$title="My advanced GUI"
GUICreate($title); will create a dialog box that when displayed is centered

GUISetControl("button", "my clicking button", 10,10)
GUISetControlNotify()

GUISetControl("button", "my closing button", 10,50)
GUISetControlEx(-1,$GUI_FOCUS)  ; the focus is on this button and Click will hide the GUI
GUIShow()      ; display the dialog box timeout 10 seconds

AdLibEnable("CheckChange")
WinWaitClose($title)  ; GuiWaitClose cannot be used to wait
AdlibDisable()

exit

Func CheckChange ()
$n = GUIMsg(0)      ; get the current state and return immediately
Select
case $n>0
    MsgBox(0,"", "the button " & GUIRead() & " has been clicked",2)
Case $n=-1
    MsgBox(0,"", "dialog box being closed by timeout",2)
    exit      ; or GuiDelete to stop the waiting WinWaitClose
case $n=-2
    MsgBox(0,"", "dialog box is hidden",2)
    GuiDelete()      ; will stop the waiting of WinWaitClose and close the script
case $n=-3
    MsgBox(0,"", "dialog box being closed by red button",2)
    exit      ; or GuiDelete to stop the waiting WinWaitClose
case $n=-4
    MsgBox(0,"", "dialog box minimized",2)
case $n=-5
    MsgBox(0,"", "dialog box restaured",2)
case $n=-6
    MsgBox(0,"", "dialog box maximize",2)
case $n=0
; no change
case else
    MsgBox(0,"", "unknown return from GUIMsg",2)
EndSelect
EndFunc

Do you use "GUINotifyMode"?

Edited by Holger

Share this post


Link to post
Share on other sites

Posted (edited)

Forgot to mention: I'm using the version that was available on the 6th of June.

I had the same problems with your example.

This works better:

AutoItSetOption("GUINotifyMode", 1)

GuiCreate("Titel")
$butMove = GuiSetControl("button","Move",50,10,70,22)
$butCopy = GuiSetControl("button","Copy",50,40,70,22)
$butConfig = GuiSetControl("button","Config",50,70,70,22)
$butCancel = GuiSetControl("button","Cancel",50,100,70,22)

GUIShow()

While 1

If GUIMsg(0) <> 0 Then
If GuiRead() = $butMove then Msgbox(0,"","Move clicked")
If GuiRead() = $butCopy then Msgbox(0,"","Copy clicked")
If GuiRead() = $butConfig Then Msgbox(0,"","Config clicked")
If GuiRead() = $butCancel OR GuiMsg(0) = -3 Then Exit
EndIf

Sleep(100)
WEnd

I used the second example you posted, and that one works fine.

Edited by SlimShady

Share this post


Link to post
Share on other sites

Posted (edited)

@SlimShady: Are you sure that you don't have a problem?

If I use your example then closing over the [x] doesn't func...

And for me it's logical:

You use these lines:

...
If GUIMsg(0) <> 0 Then
...
If GuiRead() = $butCancel OR GuiMsg(0) = -3 Then Exit

The first GUIMsg(0) realize that you have clicked at the [x] and then goes on through the code.

Then 'it' comes to the second GUIMsg(0) and checked again for a change -> but there's no change!

So the gui will never close over [x]...

Do you see what I mean?

It's better to change the line to:

If GuiRead() = $butCancel OR GuiRead() = -3 Then Exit

P.S.: in the new build you don't need a sleep cause Jon build it in - sleep(10) if you use GUIMsg(0) :D

Edited by Holger

Share this post


Link to post
Share on other sites

Posted

The problem I see, GuiWatiClose and GuiMsg() should NOT be used together. They are two completely different ways of running a GUI and shouldn't be mixed. If you need interactive or more refined control over the GUI, then GuiMsg() is your bet bet. If you want to create simple GUI's that don't need interactivity, then GuiWaitClose() is sufficient.

Share this post


Link to post
Share on other sites

Posted

Yes, it's a relative simple gui with 4 buttons. So I don't want to use a loop or AdLib. My solution so far is:

GuiCreate("Titel")
...
GuiWaitClose()

If GuiRead() = $butMove Then
   ...
ElseIf GuiRead() = $butCopy Then
   ...
ElseIf GuiRead() = $butConfig Then
   ...
Else
   Exit
EndIf

Share this post


Link to post
Share on other sites

Posted (edited)

Remove the

AutoItSetOption("GUINotifyMode", 1)

At the top of your script. In the default mode each button generates a "close" event. In "notify" mode each button click just generates an event to be used with GuiMsg()

(personally I think the default Notify mode and GuiWaitClose should be removed - they are only of use for a tiny amount of scripts and are just confusing)

Edited by Jon

Share this post


Link to post
Share on other sites

Posted

Remove the

AutoItSetOption("GUINotifyMode", 1)

At the top of your script.  In the default mode each button generates a "close" event.  In "notify" mode each button click just generates an event to be used with GuiMsg()

(personally I think the default Notify mode and GuiWaitClose should be removed - they are only of use for a tiny amount of scripts and are just confusing)

do you mean only notify?

for the guiWaitClose I was thinking it will be easier for newbies but I don't care now you leave France to win in the EUro Scoccer championship. :D

To be frank we should not have won.

Share this post


Link to post
Share on other sites

Posted

Remove the

AutoItSetOption("GUINotifyMode", 1)

At the top of your script.  In the default mode each button generates a "close" event.  In "notify" mode each button click just generates an event to be used with GuiMsg()

(personally I think the default Notify mode and GuiWaitClose should be removed - they are only of use for a tiny amount of scripts and are just confusing)

I agree with that. Unless you are making glorified message boxes, an interactive message pump is the only way to make a GUI. GuiWaitClose() is not a good introduction to GUI scripting because it employs an entirely different mindset than GuiMsg(). It does work well for doing something simple quickly, but doesn't teach anything useable in the future when wanting to make something more advanced.

Share this post


Link to post
Share on other sites

Posted

GuiWaitClose() is not a good introduction to GUI scripting because it employs an entirely different mindset than GuiMsg().  It does work well for doing something simple quickly, but doesn't teach anything useable in the future when wanting to make something more advanced.

I've thought the same thing.... Should we remove GuiWaitClose?

Share this post


Link to post
Share on other sites

Posted

I agree with that.  Unless you are making glorified message boxes, an interactive message pump is the only way to make a GUI.  GuiWaitClose() is not a good introduction to GUI scripting because it employs an entirely different mindset than GuiMsg().  It does work well for doing something simple quickly, but doesn't teach anything useable in the future when wanting to make something more advanced.

I am not sure we want to teach about the pump mechanism to newbies.

That's the reason why I implement GuiWaitClose() and GuiMsg().

If all gui are generated with the AutoBuilder everybody will have to understand the pump mechanism

Share this post


Link to post
Share on other sites

Posted

If all gui are generated with the AutoBuilder everybody will have to understand the pump mechanism

:D That means I have to maintain AutoBuilder and fix bugs :huh2:

Share this post


Link to post
Share on other sites

Posted

:D That means I have to maintain AutoBuilder and fix bugs  :)

Perhaps YES it is a so good script/application :huh2:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.