Sign in to follow this  
Followers 0
Info

GUICtrlSetStyle() with $BS_DEFPUSHBUTTON

6 posts in this topic

#1 ·  Posted (edited)

The button event should be triggered whenever I press the enter key but it isn't.

Opt("GUIOnEventMode", 1)

$g = GUICreate("gui")
$i = GUICtrlCreateInput("",2,2)
$b = GUICtrlCreateButton("click me",220,2)
GUICtrlSetStyle($b, 0x50034001);defpushbutton

GUICtrlSetOnEvent($b, "_button")
GUISetOnEvent(-3, "_Close")
GUISetState()

While 1
    Sleep(100)
WEnd

Func _button()
    MsgBox(0,"","Yay!")
EndFunc

Func _Close()
    Exit
EndFunc

It works if I set the defpushbutton style in the GUICtrlCreateButton() function but I need to set reset the style many times in my script (when the first style is not $BS_DEFPUSHBUTTON).

Edited by Info

Share this post


Link to post
Share on other sites



Yep, seems like a bug to me as well. You should search Trac and see if there's a bug ticket already, and if not you should create one.

Share this post


Link to post
Share on other sites

Guess it has something to do with the Input control, seems like the first input aquires Focus by default, kind of greedy behavior :blink:. As a workaround use GUICtrlSetState($b, $GUI_FOCUS).

Share this post


Link to post
Share on other sites

@KaFu

Not entirely true. Remove the input control and try. I get the same behavior on Win7 x64. If the DEFPUSH style is set in the call to GuiCtrlCreateButton then everything works correctly. Otherwise, same bug as OP.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You're right, it's not the input control.

$BS_DEFPUSHBUTTON = "Creates a push button with a heavy black border. If the button is in a dialog box, the user can select the button by pressing the ENTER key, even when the button does not have the input focus. This style is useful for enabling the user to quickly select the most likely option, or default."

A dialog box seems to be a window with special attributes and esp. messages, guess thats where the dog is burried (German saying :blink:)...

Edited by KaFu

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You were on to something with the dialog bit. I think there's an internal AutoIt window setting or message processing feature that needs to be 'activated'. This ugly hack works properly.

Opt("GUIOnEventMode", 1)

$g = GUICreate("gui")
$i = GUICtrlCreateInput("",2,2)
; UGLY HACK
GUICtrlDelete(GUICtrlCreateButton("" ,0 , 0, 0, 0, 1)) ; BS_DEFPUSHBUTTON
; =========
$b = GUICtrlCreateButton("click me",220,2)
GUICtrlSetStyle($b, 0x10001);ws_tabstop + defpushbutton

GUICtrlSetOnEvent($b, "_button")
GUISetOnEvent(-3, "_Close")
GUISetState()

While 1
    Sleep(100)
WEnd

Func _button()
    MsgBox(0,"","Yay!")
EndFunc

Func _Close()
    Exit
EndFunc

I'd still probably report this as a bug...

Edited by wraithdu

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