Sign in to follow this  
Followers 0
12321

[Solved] _GUICtrlButton_Create and ESC on the keyboard

4 posts in this topic

#1 ·  Posted (edited)

I wanted to create a GUI where I can use ENTER on the keyboard.

My first try was this one:

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

#include<WindowsConstants.au3>
#include<GUIConstantsEx.au3>
#include<GuiButton.au3>
#include<GuiEdit.au3>
#include<EditConstants.au3>
#include<WinAPI.au3>
#include<Constants.au3>
#include<StaticConstants.au3>

Global $GUI

_myGUI()

While WinExists($GUI)
Sleep(100)
WEnd

Func _myGUI()
$GUI = GUICreate("myGUI", 510, 150, -1, -1, -1, $WS_EX_TOPMOST)
GUISetOnEvent($GUI_EVENT_CLOSE, "_GUIclose")

Global $myGUI_input = GUICtrlCreateInput("", 15, 75, 480, 20, $SS_CENTERIMAGE)

_GUICtrlButton_Create($GUI, "Ok", 140, 110, 100, 25)
GUICtrlSetOnEvent(-1, "_button_GUI_ok")

GUICtrlCreateButton("Cancel", 270, 110, 100, 25)
GUICtrlSetOnEvent(-1, "_GUIclose")

GUISetState(@SW_SHOW)
EndFunc ;==>_myGUI

Func _button_GUI_ok()
If WinExists(@GUI_WinHandle) Then
Local $GUIposition = WinGetPos(@GUI_WinHandle)
ToolTip("Poistion x = " & $GUIposition[0] & "and y = " & $GUIposition[1])
Else
MsgBox(0,"","Why this MsgBox comes when I press ESC on the keyboard?")
EndIf
EndFunc ;==>_button_GUI_ok

Func _GUIclose()
GUIDelete(@GUI_WinHandle)
EndFunc ;==>_GUIclose

When I enter something in the input and click enter everything fine, but when (right after the creation of the GUI, without clicked enter or whatever) I enter some text in the input and click ESC on the keyboard then the function _button_GUI_ok() is called.

Why???

Okay I already solved it:

Instead of _GUICtrlButton_Create I can use GUICtrlCreateButton("Ok", 140, 110, 100, 25) and GUICtrlSetState(-1, $GUI_DEFBUTTON).

I just was wondering that's kind of a bug in _GUICtrlButton_Create or???

Edited by 12321

Share this post


Link to post
Share on other sites



12321,

You have the problem because you cannot create a control using the UDF function and then expect to action it using the GUICtrl* functions - they are used for controls created with AutoIt's native GUICtrlCreate* functions. As you can see from the example for _GUICtrlButton_Create, you need to look for the WM_COMMAND message to find out if the button was clicked. ;)

All clear? :)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Ohhhh

yes it is clear now!

Maybe I should have had a closer look to the example before using it and confusing myself :lmao:

Thanks!

Share this post


Link to post
Share on other sites

12321,

Glad I could help. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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