Jump to content

GUICtrlSetStyle() with $BS_DEFPUSHBUTTON


Info
 Share

Recommended Posts

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
Link to comment
Share on other sites

Link to comment
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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...