Jump to content

[Solved] _GUICtrlButton_Create and ESC on the keyboard


12321
 Share

Recommended Posts

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

12321,

Glad I could help. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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...