Jump to content
Sign in to follow this  

InputBox vs GUI with GUICtrlCreateInput

Recommended Posts


I know that the InputBox function is limited, and GUI with GUICtrlCreateInput is far more superior. I created two inputboxes to compare them:

InputBoxA - Created using the InputBox function:

If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Test Input Box","Please enter something...",""," ","241","141","-1","-1")
    Case @Error = 0;OK - The string returned is valid

    Case @Error = 1;The Cancel button was pushed

    Case @Error = 3;The InputBox failed to open


If @error = 0 Then MsgBox("", "", $sInputBoxAnswer)

InputBoxB - GUI with GUICtrlCreateInput:

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

$Form1 = GUICreate("Test Input Box", 241, 121, -1, -1)
$Input1 = GUICtrlCreateInput("", 8, 48, 225, 21)
$Label1 = GUICtrlCreateLabel("Please enter something.", 8, 8, 117, 17)
$Button1 = GUICtrlCreateButton("OK", 32, 80, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Cancel", 136, 80, 75, 25, 0)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Case $Button1
            $Ans = GUICtrlRead($Input1)
            MsgBox("", "", $Ans)
        Case $Button2


These two look similar, but they do not work the same. When I press "ENTER" on my keyboard on InputBoxA, it activates the "OK" button. But on InputBoxB, pressing "ENTER" on my keyboard doesn't do anything.

So my question is:

How can I make InputBoxB work like InputBoxA? How can set a default button on InputBoxB, so when I press "ENTER" on the keyboard, it will activate that button?

Thanks in advance.

Share this post

Link to post
Share on other sites

$Button1 = GUICtrlCreateButton("OK", 32, 80, 75, 25, $BS_DEFPUSHBUTTON)
Great! Thanks for the quick reply! ;)

Now the next question is.. is there a way to make InputBoxA topmost? I can do it in InputBoxB, but I'm not sure if it is possible to do that in InputBoxA.

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