Sign in to follow this  
Followers 0
CyberSlug

GUI Notification Stuff

9 posts in this topic

#1 ·  Posted (edited)

Tested with 3.0.102 May 26 version on Windows XP Pro sp2 release candidate

1) Click Button 2 with mouse. After you click OK on the popup window, Button 1 gets dotted-line focus, but the thick-black border remains around Button 2.

2) Press Alt+3. The notification for Button 1 is tiggered instead of Button 3. I assume that accelerator-keys (or whatever they are called) are not supported yet?

Also, pressing Esc (or Ctrl+Break) triggers the button with focus. This behavior can be very bad if you want a GUI to simulate MsgBox behavior where Esc/Ctrl+Break should invoke Close/Cancel... I've posted samples here where you can try pressing Esc or Ctrl+Break.

#cs - ### Generated by AutoBuilder 0.4 -- do not modify ###
394 308
0   4   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
button  $button_1   Button 1    10  20  130 50  0   0   
button  $button_2   Button 2    10  90  130 50  0   0   
button  $button_3   Button 3    10  160 130 50  0   0   
button  $button_4   Button 4    10  230 130 50  0   0   
#ce - ### End of Dump ###

Opt("GUINotifyMode", 1)
GuiCreate("MyGUI", 392,303,(@DesktopHeight-392)/2, (@DesktopHeight-303)/2 , 0x04CF0000)

$button_1 = GUISetControl("button", "Button &1", 10, 20, 130, 50)
$button_2 = GUISetControl("button", "Button &2", 10, 90, 130, 50)
$button_3 = GUISetControl("button", "Button &3", 10, 160, 130, 50)
$button_4 = GUISetControl("button", "Button &4", 10, 230, 130, 50)

GuiShow()
While 1
    sleep(100)
    $msg = GuiMsg(0)
    If $msg = -3 Then
       Exit
    ElseIf $msg > 0 Then
      MsgBox(4096,"Click", "Button #" & $msg)
   EndIf
WEnd
Exit
Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Ok, I really don't get the point of GuiMsg(0) it seems a Bad Thing ™.

Looking at the help/code it seems that GuiMsg(0) returns immediately and gives the last control played with (or 0), but what happens if other messages/controls are clicked in the time that the "Sleep(100)" happens, or during the time you process the message? You will miss events and things get out of sync.

With the correct notify mode and GuiMsg() don't you get a message each time a control is clicked anyhow without needing the whole Sleep() thing?

In fact even with GuiMsg() I'm starting to think there may be problems - it runs its own message loop but may miss events in the time you process its return result until the time you run GuiMsg() again.

Maybe this is why I get odd operation sometimes with scripts working for some people and not me...and then they suddenly start working... It all starts to make sense.

I'll have to think about a solution, but I'm thinking along the lines of a message queue that buffers events in the gui until they are read... Hmmmmmm

Edited by Jon

Share this post


Link to post
Share on other sites

Jon, GuiMsg() blocks like MessageBox or InputBox so it's not possible to use hotkeys or AdLib while it's running. You also don't get -3 (Or whatever the code is) from clicking the red close button with GuiMsg(), but you do with GuiMsg(0).

In regards to missing messages, I've found that anything above Sleep(50) creates a sluggish GUI, so that's usually what I use. I've never noticed a message being lost with that time.

I would like to see a queue, though. I think that might simplify things a bunch as it should allow moving to using only a single syntax for GuiMsg() and allow it to be non-blocking behind the scenes.

Share this post


Link to post
Share on other sites

You also don't get -3 (Or whatever the code is) from clicking the red close button with GuiMsg(), but you do with GuiMsg(0).

Yeah, why is that? Is it intentional, or a bug? Cus it just seems to be that it would be better if it did return something.

See, I'm experimenting with the GUI stuff now, and I'm having a hard time making sense of it. Currently, I just want to have a window with 2 buttons. One that executes a function, and another that closes the program, but I still want the [x] to close the program as well. What seems to be happening though is that whenever I hit the [x], the window disappears, then reappears.

My code:

Opt('GUINotifyMode', 1);

GUICreate('Run As...');

$Label = GuiSetControl('label', 'Running as USERNAME', 10, 10);
$RunButton = GUISetControl('button', 'Run Program', 10, 30);
$ExitButton = GUISetControl('button', 'Exit', 10, 60);

GUIShow();

Do
    $n = GuiMsg();
    if $n <> 0 then MsgBox(0, 'GUIMsg Status', $n)
Until $n = $ExitButton;

I get the expected/desired results from every button except the [x].

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

The fact that GuiMsg() does not return -3 for the 'x' close button is documented in the current "unstable" version of the help file, so maybe it's behaviour by design?

Saunders: You might try AutoBuilder (scripts and scraps forum)

#cs - ### Generated by AutoBuilder 0.4 -- do not modify ###
394 278
0   2   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
button  $button_1   Button 1    70  50  100 50  0   0   
button  $button_2   Button 2    230 50  100 50  0   0   
#ce - ### End of Dump ###

;Script generated by AutoBuilder 0.4 -- but modified

Opt("GUINotifyMode", 1)
GuiCreate("MyGUI", 392,273,(@DesktopWidth-392)/2, (@DesktopHeight-273)/2)
$button_1 = GUISetControl("button", "Button 1", 70, 50, 100, 50)
$button_2 = GUISetControl("button", "Close", 230, 50, 100, 50)

GuiShow()
While 1
    sleep(100)
    $msg = GuiMsg(0)
    Select
    Case $msg = -3
        ExitLoop
    Case $msg = $button_1
        MsgBox(4096,"","Button 1 Clicked")
    Case $msg = $button_2
        ExitLoop
    EndSelect
WEnd
Exit
Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

The fact that GuiMsg() does not return -3 for the 'x' close button is documented in the current "unstable" version of the help file, so maybe it's behaviour by design?

You mean this part?

Closing: -3 dialog box being closed with Windows title bar close button (Cross Red button).

Only valid for Opt("GuiNotifyMode",1) or GuiMsg(0) return.

I have GuiNotifyMode set to 1 though, and it still doesn't want to cooperate. Crazy thing.

Saunders:  You might try AutoBuilder (scripts and scraps forum)

Actually, I do have AutoBuilder (nice application, good job), but I'm having more fun doing everything by hand right now. :D

Is that the only way to get the [x] to work though? An infinite sleeping loop with GuiMsg(0)?

Thanks again.

Edited by Saunders

Share this post


Link to post
Share on other sites

@saunders

Only valid for Opt("GuiNotifyMode",1) or GuiMsg(0) return.

This info apply to minimized/maximized/restored not to closing

I will change the doc to have a better formating :D

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