Sign in to follow this  
Followers 0
Graywalker

VERY ODD bug (Workaround)

18 posts in this topic

#1 ·  Posted (edited)

Can't post the code because it is 2217 lines of it, but...

- Environment : AutoIT3 v3.3.6.1 ; coding on a Windows 7, 64 bit machine, compiling into x86 exe -

I have a GUI that is using some other GUIs I have written as helper apps. Basic form is :

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ServiceControl.au3>
#include <Constants.au3>

Opt("GUIOnEventMode", 1)
Opt("GUIDataSeparatorChar", "|")

$ComputerName = @ComputerName

Global $Form1 = GUICreate("TheForm", 200, 400, 189, 122, $WS_OVERLAPPEDWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "FormClose")
GUISetBkColor(0x003366, $Form1)

$CnameInput = GUICtrlCreateInput($ComputerName, 50, 100, 121, 21)
GUICtrlSetOnEvent($CnameInput, "ButtonsClick")

$Dummy = GUICtrlCreateButton("",80,150,10,10,$BS_DEFPUSHBUTTON)
GUICtrlSetState($Dummy, $GUI_FOCUS)
GUICtrlSetOnEvent($Dummy,"ButtonsClick")

; Some Helper app ----->
$Service2ButtonAdmin = GUICtrlCreateButton("MyHelperApp", 50, 200, 75, 25)
GUICtrlSetOnEvent($Service2ButtonAdmin, "stHelperApp")
GUICtrlSetCursor($Service2ButtonAdmin, 0)
GUICtrlSetBkColor($Service2ButtonAdmin, 0xA6CAF0)
; <---- Some Helper app

; Some Helper app2 ----->
$Service3ButtonAdmin = GUICtrlCreateButton("MyHelperApp2", 50, 300, 75, 25)
GUICtrlSetOnEvent($Service3ButtonAdmin, "ndHelperApp")
GUICtrlSetCursor($Service3ButtonAdmin, 0)
GUICtrlSetBkColor($Service3ButtonAdmin, 0xA6CAF0)
; <---- Some Helper app2
GUISetState(@SW_SHOW)
; Gui Loop
While 1
    Sleep(100)
WEnd
; < - - - Gui Loop

Func ButtonsClick()
    GUISetCursor(1)
    $Selection = GUICtrlRead($CnameInput)
    MsgBox(0,"Button Click!","Your Computer Name is " & $Selection)
    GUISetCursor(2)
GUICtrlSetState($Dummy, $BS_DEFPUSHBUTTON)
EndFunc   ;==>ButtonsClick

Func stHelperApp()
    MsgBox(0,"Helper App!",'ShellExecute(@ScriptDir & "\1stHelperApp.exe", "Option1"')
    GUICtrlSetState($Dummy, $BS_DEFPUSHBUTTON)
EndFunc   ;==>1stHelperApp

Func ndHelperApp()
    MsgBox(0,"Helper App!",'@ScriptDir & "\2ndHelperApp.exe", "Option2"')
    GUICtrlSetState($Dummy, $BS_DEFPUSHBUTTON)
EndFunc   ;==>2ndHelperApp

Func FormClose()
    Exit
EndFunc   ;==>Form1Close

I've had this code working for a long time. I made some adjustments, including using GuiSetCursor(1), and it started doing this weird thing.

Once I've opened a helper app, then close the helper app, any time I press "Enter", it will reopen the last opened helper app.

?????

http://www.autoitscript.com/trac/autoit/ticket/1748

Edited by Graywalker

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

When compiled and ran on an XP machine, the "Enter" bug still occurs.

Using trace lines I get :

@@ Trace(3515) :    EndFunc   ;==>_History
>Error code: 0

@@ Trace(1582) :        GUICtrlDelete($templabel6)
>Error code: 0

@@ Trace(1584) :        GUISetCursor(2)
>Error code: 0

@@ Trace(1587) :    EndFunc   ;==>ButtonsClick
>Error code: 0

@@ Trace(3068) :        ShellExecute(@ScriptDir & "\TaskScheduler.exe", $ComputerName)
>Error code: 0

@@ Trace(3070) :    EndFunc   ;==>ScheduleTask
>Error code: 0

@@ Trace(671) :    WEnd
>Error code: 0

@@ Trace(669) :     Sleep(100)
>Error code: 0

With further testing, pressing enter any time when the GUI is active, no matter where on the GUI I am, it executes the last "ShellExecute" or last function that ran.

I have no hotkeys set.

Anybody think of anything that could cause this??

Edited by Graywalker

Share this post


Link to post
Share on other sites

Well that has to be the sorriest reproducer script ever posted. Did you even try running Tidy, Syntax Checker, or a compile on it?

This is cleaned up demo:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $GuiStyle = BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, _
        $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, _
        $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS)
Global $Form1 = GUICreate("TheForm", 300, 300, -1, -1, $GuiStyle)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")

; Some Helper app ----->
$Service2ButtonAdmin = GUICtrlCreateButton("MyHelperApp", 100, 100, 100, 30)
GUICtrlSetOnEvent($Service2ButtonAdmin, "FirstHelperApp")
GUICtrlSetCursor($Service2ButtonAdmin, 0)

; Some Helper app2 ----->
$Service3ButtonAdmin = GUICtrlCreateButton("MyHelperApp2", 100, 200, 100, 30)
GUICtrlSetOnEvent($Service3ButtonAdmin, "SecondHelperApp")
GUICtrlSetCursor($Service3ButtonAdmin, 0)

GUISetState()

; Gui Loop
While 1
    Sleep(100)
WEnd

Func FirstHelperApp()
    ConsoleWrite("Debug:  FirstHelperApp.exe" & @LF)
EndFunc   ;==>FirstHelperApp

Func SecondHelperApp()
    ConsoleWrite("Debug:  SecondHelperApp.exe" & @LF)
EndFunc   ;==>SecondHelperApp

Func Form1Close()
    Exit
EndFunc   ;==>Form1Close

The latest button you click is now the default.

Hitting enter (outside of a multi-line Edit control with $ES_WANTRETURN style) simulates clicking the default button.

I'm pretty sure you can turn that behavior off with a GUI Style setting, or something, but can't remember where right now.

At least you have a working demo to try it on.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Well that has to be the sorriest reproducer script ever posted. Did you even try running Tidy, Syntax Checker, or a compile on it?

The latest button you click is now the default.

Hitting enter (outside of a multi-line Edit control with $ES_WANTRETURN style) simulates clicking the default button.

I'm pretty sure you can turn that behavior off with a GUI Style setting, or something, but can't remember where right now.

At least you have a working demo to try it on.

;)

:) Sorry... I wrote that in the forum entry box... no tidy, etc. Re-did it a bit.

Thanks for pointing in (hopefully) the right direction!!

;)

I did discover one thing - I had WAAAAY to many things in the BitOR()!! Its now :

Global $Form1 = GUICreate("TheForm", 647, 600, 189, 122, BitOR($WS_SIZEBOX, $WS_OVERLAPPEDWINDOW))
Edited by Graywalker

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

So far I have been unable to find any way to work around the "new" "pressing enter is the same as clicking the default button on a gui" that I can not find any documentation for either.

I've tried using $BS_DEFPUSHBUTTON to set a default button :

Global $Dummy = GUICtrlCreateButton("db",626,585,5,5,$BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent($Dummy,"ButtonsClick")

but apparently, no matter what you do, the last button you clicked is the Default that is "clicked" when you press "Enter"

and - no way to turn it off - so far. Even when I am inside an input box. Pressing enter after typing creates an event for the input box AND the last button clicked. Where does that make sense??

Is there any way to capture the pressing of an enter key event? (using OnEvent Mode) How about turning off this Wonderful ;) "last button clicked is the default" feature? I can't find one documented so far.

Edited by Graywalker

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This might work for you:

GUICtrlSetOnEvent($Service2ButtonAdmin, "FirstHelperApp")
GUICtrlSetCursor($Service2ButtonAdmin, 0)

; Some Helper app2 ----->
$Service3ButtonAdmin = GUICtrlCreateButton("MyHelperApp2", 100, 200, 100, 30)
GUICtrlSetOnEvent($Service3ButtonAdmin, "SecondHelperApp")
GUICtrlSetCursor($Service3ButtonAdmin, 0)

$dummy = GUICtrlCreateButton("", 100, 300, 100, 30)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetState(-1, $GUI_FOCUS)

GUISetState()

; Gui Loop
While 1
    Sleep(100)
WEnd

Func FirstHelperApp()
    GUICtrlSetState($dummy, $GUI_FOCUS)
    ToolTip("BUTTON 1 PRESSED")
    Beep(800,50)
EndFunc   ;==>FirstHelperApp

Func SecondHelperApp()
    GUICtrlSetState($dummy, $GUI_FOCUS)
    ToolTip("BUTTON 2 PRESSED")
    Beep(800,50)
EndFunc   ;==>SecondHelperApp

Func Form1Close()
    Exit
EndFunc   ;==>Form1Close

It just puts the focus back on a hidden dummy button when another button was pressed. You can still TAB through the buttons and still use ENTER to send the button (but not consequitively, as it loses focus each time).

Edit: Or, just insert your own logic to move the focus around in some user-friendly manner.

Edited by Spiff59

Share this post


Link to post
Share on other sites

This might work for you:

Thank you for the suggestion!!

I've tested something similar, but it appears that when using Opt("GUIOnEventMode", 1) the GUI just sits there waiting on an event. It never goes back through the lines above the loop, so once the focus is lost, it will never go back.

Wouldn't you need to put the

GUICtrlSetState($dummy, $GUI_FOCUS)

in every function?

I put the following in my code and it did not change the unwanted behavior.

$dummy = GUICtrlCreateButton("", 100, 300, 100, 30)
GUICtrlSetState($dummy, $GUI_HIDE)
GUICtrlSetState($dummy, $GUI_FOCUS)
GUICtrlSetOnEvent($dummy,"ButtonsClick")

Then I went and put the GUICtrlSetState($dummy, $GUI_FOCUS) in two of the functions and tested - no change. ;)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Okay, got a better and more specific reproducer script.

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ServiceControl.au3>
#include <Constants.au3>

Opt("GUIOnEventMode", 1)
Opt("GUIDataSeparatorChar", "|")

$ComputerName = @ComputerName

Global $Form1 = GUICreate("TheForm", 200, 400, 189, 122, $WS_OVERLAPPEDWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "FormClose")
GUISetBkColor(0x003366, $Form1)

$CnameInput = GUICtrlCreateInput($ComputerName, 50, 100, 121, 21)
GUICtrlSetOnEvent($CnameInput, "InputChange")

$Dummy = GUICtrlCreateButton("", 80, 150, 10, 10, $BS_DEFPUSHBUTTON)
GUICtrlSetState($Dummy, $GUI_FOCUS)
GUICtrlSetOnEvent($Dummy, "InputChange")

; Some Helper app ----->
$Service2ButtonAdmin = GUICtrlCreateButton("MyHelperApp", 50, 200, 75, 25)
GUICtrlSetOnEvent($Service2ButtonAdmin, "stHelperApp")
GUICtrlSetCursor($Service2ButtonAdmin, 0)
GUICtrlSetBkColor($Service2ButtonAdmin, 0xA6CAF0)
; <---- Some Helper app

; Some Helper app2 ----->
$Service3ButtonAdmin = GUICtrlCreateButton("MyHelperApp2", 50, 300, 75, 25)
GUICtrlSetOnEvent($Service3ButtonAdmin, "ndHelperApp")
GUICtrlSetCursor($Service3ButtonAdmin, 0)
GUICtrlSetBkColor($Service3ButtonAdmin, 0xA6CAF0)
; <---- Some Helper app2
GUISetState(@SW_SHOW)
; Gui Loop
While 1
    Sleep(100)
WEnd
; < - - - Gui Loop

Func InputChange()
    GUISetCursor(1)
    $Selection = GUICtrlRead($CnameInput)
    MsgBox(0, "Button Click!", "Your Computer Name is " & $Selection)
    GUISetCursor(2)
    ;GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
EndFunc   ;==>InputChange

Func stHelperApp()
    MsgBox(0, "Helper App!", 'ShellExecute(@ScriptDir & "\1stHelperApp.exe", "Option1"')
    ;GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
EndFunc   ;==>stHelperApp

Func ndHelperApp()
    MsgBox(0, "Helper App!", '@ScriptDir & "\2ndHelperApp.exe", "Option2"')
    ;GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
EndFunc   ;==>ndHelperApp

Func FormClose()
    Exit
EndFunc   ;==>FormClose

I've included a few proposed solutions in the script too.

To reproduce the problem :

1) run script.

2) Press "Enter"

3) Click on "MyHelperApp" button and close the message box

4) Click in the Input and change the name to "Changed" (or anything) - CLICK anywhere (do not press "Enter")

5) Click inside the Input and press "Enter"

6) Click the MyHelperApp2 and close the message box

7) Change the text and press "Enter" - here you will see the expected behavior of the "Your computer name is" THEN MyHelperApp2 pops up too.

If you remove the ; from ;GUICtrlSetState($Dummy, $GUI_DEFBUTTON) in each Func, you get a double action when pressing "Enter" while in the input.

When I press "Enter" any time, I want "InputChange" to run - nothing else. Not app1 not app2 - only "InputChange" - now if I had more than one input box, I'd probably want it to move on to the next box or run the "Save" or "Input" or "Next" button's action. I don't think there is ANY instance where I would WANT "Enter" to re-run the last button they clicked no matter what it was. That leaves me with NO control over what my GUI does. In my "Production" GUI, I have at least 23 buttons, a refresh icon, a Combo box and one Input. It is expected that when making changes in the text of the input that "Enter" puts those changes into effect. Granted, AutoIT3 puts those changes into effect whenever the input looses focus, but still, in an input, "Enter" should be the same as the input losing focus - it confirms the change. It should NOT also launch the last button clicked.

Am I missing a way to control what "Enter" does in my GUI?

Edited by Graywalker

Share this post


Link to post
Share on other sites

You would put the GuiCtrlSetState() in each of the button event handlers. So when each button is done being handled, the focus goes back to the dummy.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $GuiStyle = BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, _
        $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, _
        $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS)
Global $Form1 = GUICreate("TheForm", 300, 300, -1, -1, $GuiStyle)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")

; Some Helper app ----->
$Service2ButtonAdmin = GUICtrlCreateButton("MyHelperApp", 100, 100, 100, 30)
GUICtrlSetOnEvent($Service2ButtonAdmin, "FirstHelperApp")

; Some Helper app2 ----->
$Service3ButtonAdmin = GUICtrlCreateButton("MyHelperApp2", 100, 200, 100, 30)
GUICtrlSetOnEvent($Service3ButtonAdmin, "SecondHelperApp")

; Dummy button
$idDummy = GUICtrlCreateButton("Dummy", 350, 350)
GUICtrlSetState($idDummy, $GUI_HIDE)
ControlFocus($Form1, "", $idDummy)

GUISetState()

; Gui Loop
While 1
    Sleep(100)
WEnd

Func FirstHelperApp()
    ConsoleWrite("Debug:  FirstHelperApp.exe" & @LF)
    ControlFocus($Form1, "", $idDummy)
EndFunc   ;==>FirstHelperApp

Func SecondHelperApp()
    ConsoleWrite("Debug:  SecondHelperApp.exe" & @LF)
    ControlFocus($Form1, "", $idDummy)
EndFunc   ;==>SecondHelperApp

Func Form1Close()
    Exit
EndFunc   ;==>Form1Close

I still think this behavior can be controlled by the GUI settings, but I'm also still too lazy to look for it.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You would put the GuiCtrlSetState() in each of the button event handlers. So when each button is done being handled, the focus goes back to the dummy.

Tested with the following code.

Resulted in another odd behavior. Pressing "Enter" anywhere outside the input, launched the code associated with the $Dummy. When changing the text in the input and pressing enter, the Input change code ran, followed by the msgbox from the last clicked button. Similar to the "GUICtrlSetState($Dummy, $GUI_DEFBUTTON)" attempt (commented out) which resulted in double function calls.

and I have been searching and searching the documentation, specifically the GUI stuff, and one possible mention of this behavior, but no way to turn it off. The one possible mention being :

"$ES_WANTRETURN 0x1000 Specifies that a carriage return be inserted when the user presses the ENTER key while typing text into a multiline edit control in a dialog box. If you do not specify this style, pressing the ENTER key has the same effect as pressing the dialog box’s default push button. This style has no effect on a single-line edit control."

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ServiceControl.au3>
#include <Constants.au3>

Opt("GUIOnEventMode", 1)
Opt("GUIDataSeparatorChar", "|")

$ComputerName = @ComputerName

Global $Form1 = GUICreate("TheForm", 200, 400, 189, 122, $WS_OVERLAPPEDWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "FormClose")
GUISetBkColor(0x003366, $Form1)

$CnameInput = GUICtrlCreateInput($ComputerName, 50, 100, 121, 21)
GUICtrlSetOnEvent($CnameInput, "InputChange")

$Dummy = GUICtrlCreateButton("", 80, 150, 10, 10, $BS_DEFPUSHBUTTON)
GUICtrlSetState($Dummy, $GUI_FOCUS)
GUICtrlSetOnEvent($Dummy, "InputChange")

; Some Helper app ----->
$Service2ButtonAdmin = GUICtrlCreateButton("MyHelperApp", 50, 200, 75, 25)
GUICtrlSetOnEvent($Service2ButtonAdmin, "stHelperApp")
GUICtrlSetCursor($Service2ButtonAdmin, 0)
GUICtrlSetBkColor($Service2ButtonAdmin, 0xA6CAF0)
; <---- Some Helper app

; Some Helper app2 ----->
$Service3ButtonAdmin = GUICtrlCreateButton("MyHelperApp2", 50, 300, 75, 25)
GUICtrlSetOnEvent($Service3ButtonAdmin, "ndHelperApp")
GUICtrlSetCursor($Service3ButtonAdmin, 0)
GUICtrlSetBkColor($Service3ButtonAdmin, 0xA6CAF0)
; <---- Some Helper app2
GUISetState(@SW_SHOW)
; Gui Loop
While 1
    Sleep(100)
WEnd
; < - - - Gui Loop

Func InputChange()
    GUISetCursor(1)
    $Selection = GUICtrlRead($CnameInput)
    MsgBox(0, "Button Click!", "Your Computer Name is " & $Selection)
    GUISetCursor(2)
    ;GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
    ControlFocus($Form1, "", $Dummy)

EndFunc   ;==>InputChange

Func stHelperApp()
    MsgBox(0, "Helper App!", 'ShellExecute(@ScriptDir & "\1stHelperApp.exe", "Option1"')
    ;GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
    ControlFocus($Form1, "", $Dummy)
EndFunc   ;==>stHelperApp

Func ndHelperApp()
    MsgBox(0, "Helper App!", '@ScriptDir & "\2ndHelperApp.exe", "Option2"')
    ;GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
    ControlFocus($Form1, "", $Dummy)
EndFunc   ;==>ndHelperApp

Func FormClose()
    Exit
EndFunc   ;==>FormClose

Share this post


Link to post
Share on other sites

Why did you associate InputChange() with the $Dummy button? You misunderstood the whole point of having a "Dummy" button in the first place.

Remove that GUICtrlSetOnEvent() and it works fine.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Why did you associate InputChange() with the $Dummy button? You misunderstood the whole point of having a "Dummy" button in the first place.

Remove that GUICtrlSetOnEvent() and it works fine.

:)

Thank you very much for your efforts at finding a solution, it is greatly appreciated.

Changed the code and, well, it kind of works fine. Until you change the text in the input box and press "Enter" - then it does both the input and the last button clicked. Pressing "Enter" anywhere else does nothing - which is better, to be sure! But if I click a button, click OK on the msgbox and press "Enter" - the msgbox opens again! - but click OK to close it and press "Enter" again, it doesn't open again. Its much better, but still not reliable.

Maybe I can tell users its a "Feature" ;)

"Change the name in the input box and press tab to activate it. As an added feature, if you change the name and press Enter instead of tab, it also runs the last button clicked!" ;)

Yes, one reason I am so picky on this is that I have a program that is fairly widely used in the department that has users who expect certain behavior from it. Now it has changed... and users don't like change. "but I used to be able to just press Enter!" "it didn't used to do that!"

I've put it in as a bug. :P Since I can't find any documentation where it can be turned off - and I have searched.

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ServiceControl.au3>
#include <Constants.au3>

Opt("GUIOnEventMode", 1)
Opt("GUIDataSeparatorChar", "|")

$ComputerName = @ComputerName

Global $Form1 = GUICreate("TheForm", 200, 400, 189, 122, $WS_OVERLAPPEDWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "FormClose")
GUISetBkColor(0x003366, $Form1)

$CnameInput = GUICtrlCreateInput($ComputerName, 50, 100, 121, 21)
GUICtrlSetOnEvent($CnameInput, "InputChange")

$Dummy = GUICtrlCreateButton("", 80, 150, 10, 10, $BS_DEFPUSHBUTTON)
GUICtrlSetState($Dummy, $GUI_FOCUS)
GuiCtrlSetState($Dummy, $GUI_HIDE)
;GUICtrlSetOnEvent($Dummy, "InputChange")

; Some Helper app ----->
$Service2ButtonAdmin = GUICtrlCreateButton("MyHelperApp", 50, 200, 75, 25)
GUICtrlSetOnEvent($Service2ButtonAdmin, "stHelperApp")
GUICtrlSetCursor($Service2ButtonAdmin, 0)
GUICtrlSetBkColor($Service2ButtonAdmin, 0xA6CAF0)
; <---- Some Helper app

; Some Helper app2 ----->
$Service3ButtonAdmin = GUICtrlCreateButton("MyHelperApp2", 50, 300, 75, 25)
GUICtrlSetOnEvent($Service3ButtonAdmin, "ndHelperApp")
GUICtrlSetCursor($Service3ButtonAdmin, 0)
GUICtrlSetBkColor($Service3ButtonAdmin, 0xA6CAF0)
; <---- Some Helper app2
GUISetState(@SW_SHOW)
; Gui Loop
While 1
    Sleep(100)
WEnd
; < - - - Gui Loop

Func InputChange()
    GUISetCursor(1)
    $Selection = GUICtrlRead($CnameInput)
    MsgBox(0, "Button Click!", "Your Computer Name is " & $Selection)
    GUISetCursor(2)
    ;GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
    ControlFocus($Form1, "", $Dummy)

EndFunc   ;==>InputChange

Func stHelperApp()
    MsgBox(0, "Helper App!", 'ShellExecute(@ScriptDir & "\1stHelperApp.exe", "Option1"')
    ;GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
    ControlFocus($Form1, "", $Dummy)
EndFunc   ;==>stHelperApp

Func ndHelperApp()
    MsgBox(0, "Helper App!", '@ScriptDir & "\2ndHelperApp.exe", "Option2"')
    ;GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
    ControlFocus($Form1, "", $Dummy)
EndFunc   ;==>ndHelperApp

Func FormClose()
    Exit
EndFunc   ;==>FormClose

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I think this is not a bug. We haven't gotten past debugging your own code yet. I'm still not clear on what you want to happen. This version will trigger the appropriate events for the two buttons, and an event for hitting enter on the Input box, yet not react anywhere else. There is nothing extra happening when the MsgBox() is closed.

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("GUIDataSeparatorChar", "|")

$ComputerName = @ComputerName

Global $Form1 = GUICreate("TheForm", 200, 400, 189, 122, $WS_OVERLAPPEDWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "FormClose")

$CnameInput = GUICtrlCreateInput($ComputerName, 50, 100, 121, 21)

$Dummy = GUICtrlCreateButton("", 80, 150, 10, 10, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent($Dummy, "InputChange")
GUICtrlSetState($Dummy, $GUI_HIDE)

; Some Helper app ----->
$Service2ButtonAdmin = GUICtrlCreateButton("MyHelperApp", 50, 200, 75, 25)
GUICtrlSetOnEvent($Service2ButtonAdmin, "FirstHelperApp")
GUICtrlSetCursor($Service2ButtonAdmin, 0)

; Some Helper app2 ----->
$Service3ButtonAdmin = GUICtrlCreateButton("MyHelperApp2", 50, 300, 75, 25)
GUICtrlSetOnEvent($Service3ButtonAdmin, "SecondHelperApp")
GUICtrlSetCursor($Service3ButtonAdmin, 0)

GUISetState(@SW_SHOW)
ControlFocus($Form1, "", $CnameInput)
$ClassNnInput = ControlGetFocus($Form1, "")

; Gui Loop
While 1
    Sleep(100)
WEnd

Func InputChange()
    If ControlGetFocus($Form1, "") == $ClassNnInput Then
        $Selection = GUICtrlRead($CnameInput)
        MsgBox(0, "Button Click!", "Your Computer Name is " & $Selection)
        GUISetCursor(2)
        ControlFocus($Form1, "", $Dummy)
    EndIf
EndFunc   ;==>InputChange

Func FirstHelperApp()
    MsgBox(0, "First Helper App!", 'First Helper App!')
    ControlFocus($Form1, "", $Dummy)
EndFunc   ;==>FirstHelperApp

Func SecondHelperApp()
    MsgBox(0, "Second Helper App!", 'Second Helper App!')
    ;GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
    ControlFocus($Form1, "", $Dummy)
EndFunc   ;==>SecondHelperApp

Func FormClose()
    Exit
EndFunc   ;==>FormClose

If that's not the behavior you wanted, what is?

Don't worry about bugs until you can code a simple example of something that should work, but doesn't. You aren't there yet.

;)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Got a simple, one line of code, work around....

HotKeySet("{ENTER}", "ButtonsClick")

But it has a different unwanted effect... NOTHING else can use "Enter" for anything. I had to close the test run to press enter to get a new line while writing this. So... nope... no good.

Did some more testing on the ControlFocus($Form1, "", $Dummy) suggestion. It also causes a double func call when "Enter" is pressed while inside a ListView control.

Then, I found a workaround that actually works reliably so far. Its ugly and I'm not sure what performance effects it may have on slower boxes, if any, but :

While 1
    Sleep(100)
    GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
WEnd

Making the full code to reproduce :

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ServiceControl.au3>
#include <Constants.au3>

Opt("GUIOnEventMode", 1)
Opt("GUIDataSeparatorChar", "|")

$ComputerName = @ComputerName

Global $Form1 = GUICreate("TheForm", 200, 400, 189, 122, $WS_OVERLAPPEDWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "FormClose")
GUISetBkColor(0x003366, $Form1)

$CnameInput = GUICtrlCreateInput($ComputerName, 50, 100, 121, 21)
GUICtrlSetOnEvent($CnameInput, "InputChange")

$Dummy = GUICtrlCreateButton("", 80, 150, 10, 10, $BS_DEFPUSHBUTTON)
GUICtrlSetState($Dummy, $GUI_FOCUS)
GuiCtrlSetState($Dummy, $GUI_HIDE)
;GUICtrlSetOnEvent($Dummy, "InputChange")

; Some Helper app ----->
$Service2ButtonAdmin = GUICtrlCreateButton("MyHelperApp", 50, 200, 75, 25)
GUICtrlSetOnEvent($Service2ButtonAdmin, "stHelperApp")
GUICtrlSetCursor($Service2ButtonAdmin, 0)
GUICtrlSetBkColor($Service2ButtonAdmin, 0xA6CAF0)
; <---- Some Helper app

; Some Helper app2 ----->
$Service3ButtonAdmin = GUICtrlCreateButton("MyHelperApp2", 50, 300, 75, 25)
GUICtrlSetOnEvent($Service3ButtonAdmin, "ndHelperApp")
GUICtrlSetCursor($Service3ButtonAdmin, 0)
GUICtrlSetBkColor($Service3ButtonAdmin, 0xA6CAF0)
; <---- Some Helper app2
GUISetState(@SW_SHOW)
; Gui Loop
While 1
    Sleep(100)
    GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
WEnd
; < - - - Gui Loop

Func InputChange()
    GUISetCursor(1)
    $Selection = GUICtrlRead($CnameInput)
    MsgBox(0, "Button Click!", "Your Computer Name is " & $Selection)
    GUISetCursor(2)
    ;GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
    ;ControlFocus($Form1, "", $Dummy)

EndFunc   ;==>InputChange

Func stHelperApp()
    MsgBox(0, "Helper App!", 'ShellExecute(@ScriptDir & "\1stHelperApp.exe", "Option1"')
    ;GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
    ;ControlFocus($Form1, "", $Dummy)
EndFunc   ;==>stHelperApp

Func ndHelperApp()
    MsgBox(0, "Helper App!", '@ScriptDir & "\2ndHelperApp.exe", "Option2"')
    ;GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
    ;ControlFocus($Form1, "", $Dummy)
EndFunc   ;==>ndHelperApp

Func FormClose()
    Exit
EndFunc   ;==>FormClose

Share this post


Link to post
Share on other sites

I think this is not a bug. We haven't gotten past debugging your own code yet. I'm still not clear on what you want to happen. This version will trigger the appropriate events for the two buttons, and an event for hitting enter on the Input box, yet not react anywhere else. There is nothing extra happening when the MsgBox() is closed.

If that's not the behavior you wanted, what is?

Don't worry about bugs until you can code a simple example of something that should work, but doesn't. You aren't there yet.

;)

Yep. That works - if you want to add an extra button and an extra line of code for each and every function in your GUI. Which is fine if you have a GUI that only does one or two things. When you have a GUI that does 40 or more things, adding 43 lines of work-around code to a GUI that was previously working just fine is really annoying.

If all you are doing with AutoIT is "Yes/No" or "Retry/Abort/Continue" pop-ups, then you're kind of wasting the language.

This will have to be done with EVERY Function of EVERY GUI that doesn't want to have "Enter" call up the last button clicked - even when entering text in an input box or having been in a List View.

"A software bug is the common term used to describe an error, flaw, mistake, failure, or fault in a computer program or system that produces an incorrect or unexpected result, or causes it to behave in unintended ways. ..." http://en.wikipedia.org/wiki/Software_bug

Expected Behavior of an Input Box is to accept and or process the text when "Enter" is pressed.

The Default behavior of an Input Box (without all the work around code) after a button has been clicked is now to accept the text AND launch the last button clicked. I think that fits the definition of a bug. Even if there is a work-around code for it.

I've posted several examples of code that should work - and does - only with unexpected side effects. (except the first one, which was hastily done) A GUI should NOT require the dummy button and whatever extra code just to behave as expected.

Share this post


Link to post
Share on other sites

You are correct this is a bug which was reported as #376. Unfortunately for you it has been marked as won't fix as apparently it would require a major re-write of AutoIt's GUI code. The lines in your code that are causing the problem are the GUICtrlSetBkColor() where you set the background colour of the buttons which has the unwanted side effect of also makeing the buttons respond as if they had the $BS_DEFPUSHBUTTON style set. If you comments out these lines and accept the default button colours you will see that your script will work as expected.

If you really want your buttons to be a different colour you could try using clickable images instead.   


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

The lines in your code that are causing the problem are the GUICtrlSetBkColor() where you set the background colour of the buttons which has the unwanted side effect of also makeing the buttons respond as if they had the $BS_DEFPUSHBUTTON style set.

Ouch. I remember that bug now. I was deleting all the extraneous stuff from Graywalker's demo to simplify it, including all the color changes, so I didn't see that.

To quote the sage Homer: Doh!

;)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

You are correct this is a bug which was reported as #376. Unfortunately for you it has been marked as won't fix as apparently it would require a major re-write of AutoIt's GUI code. The lines in your code that are causing the problem are the GUICtrlSetBkColor() where you set the background colour of the buttons which has the unwanted side effect of also makeing the buttons respond as if they had the $BS_DEFPUSHBUTTON style set. If you comments out these lines and accept the default button colours you will see that your script will work as expected.

If you really want your buttons to be a different colour you could try using clickable images instead.   

... DOAH!

Thank you! ... now to see if I can make some nice button images...

Still, the Four-line workaround is functional. Still not sure if putting the

While 1
    Sleep(100)
    GUICtrlSetState($Dummy, $GUI_DEFBUTTON)
WEnd

in the Sleep loop is a good thing or not...

Edited by Graywalker

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