Jump to content

Recommended Posts

Posted

When an input contains a default value, and the program focuses on that input, the value is automatically selected, so when the user begins to type, it is cleared.

My question: how to remove the auto-selection?

Here a simple code

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>


$hWnd = GUICreate("Input without preselected input", 400, 300)
GUISetFont(14, 400, 1, "DOSLike")

$btnOK = GUICtrlCreateButton("&OK", 260, 248, 80, 30, 0)
$input1 = GUICtrlCreateInput("Value1", 20, 24, 200, 24)
$input2 = GUICtrlCreateInput("Value2", 20, 80, 200, 24)

GUISetState()
GUICtrlSetState($input2, $GUI_FOCUS) ; here we focus to the second input

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3, $GUI_EVENT_CLOSE, $btnOK
            Exit
    EndSwitch
WEnd
  • Moderators
Posted

charvi,

Send a "HOME" after setting the focus:

GUICtrlSetState($input2, $GUI_FOCUS); here we focus to the second input
Send("{HOME}")

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:

  Reveal hidden contents

 

Posted

You also can use GUICtrlSendMsg with $EM_SETSEL (it's more reliable that way):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
;

$hWnd = GUICreate("Input without preselected input", 400, 300)
GUISetFont(14, 400, 1, "DOSLike")

$btnOK = GUICtrlCreateButton("&OK", 260, 248, 80, 30, 0)
$input1 = GUICtrlCreateInput("Value1", 20, 24, 200, 24)
$input2 = GUICtrlCreateInput("Value2", 20, 80, 200, 24)

GUISetState()

GUICtrlSetState($input2, $GUI_FOCUS) ; here we focus to the second input
GUICtrlSendMsg($input2, $EM_SETSEL, -1, -1) ; and here we set the selection at the end of input control

While 1
    $nMsg = GUIGetMsg()
   
    Switch $nMsg
        Case -3, $GUI_EVENT_CLOSE, $btnOK
            Exit
    EndSwitch
WEnd

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

  MrCreatoR said:

You also can use GUICtrlSendMsg with $EM_SETSEL (it's more reliable that way):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
;

$hWnd = GUICreate("Input without preselected input", 400, 300)
GUISetFont(14, 400, 1, "DOSLike")

$btnOK = GUICtrlCreateButton("&OK", 260, 248, 80, 30, 0)
$input1 = GUICtrlCreateInput("Value1", 20, 24, 200, 24)
$input2 = GUICtrlCreateInput("Value2", 20, 80, 200, 24)

GUISetState()

GUICtrlSetState($input2, $GUI_FOCUS) ; here we focus to the second input
GUICtrlSendMsg($input2, $EM_SETSEL, -1, -1) ; and here we set the selection at the end of input control

While 1
    $nMsg = GUIGetMsg()
   
    Switch $nMsg
        Case -3, $GUI_EVENT_CLOSE, $btnOK
            Exit
    EndSwitch
WEnd
Thank you for your reply MrCreatoR, this is indeed a good thing to know too.

But what is the real difference/advantage with the use of GUICtrlSendMsg() against Send()? Your example also works with the more human-readable Send("{End}"). You told it's more reliable, does this mean that Send() is not reliable enough in some circumstances?

For example, when I make an input where I'm giving the user a typing facility by locating the caret at the 5th position, I'm using the Melba23 idea (in the case a number for 95% should begin with '555-'):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

$hWnd = GUICreate("Input with caret at desired position", 350, 130)
GUISetFont(14, 400, 1, "DOSLike")

$btnOK = GUICtrlCreateButton("&OK", 218, 70, 80, 30, 0)
GUICtrlCreateLabel("Number: ", 20, 24, 200, 20)
$input1 = GUICtrlCreateInput("555-123-456", 100, 22, 200, 24)

GUISetState()
GUICtrlSetState($input1, $GUI_FOCUS)
Send("{Home}{Right}{Right}{Right}{Right}")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3, $GUI_EVENT_CLOSE, $btnOK
            Exit
    EndSwitch
WEnd
Posted

  Quote

But what is the real difference/advantage with the use of GUICtrlSendMsg() against Send()? Your example also works with the more human-readable Send("{End}"). You told it's more reliable, does this mean that Send() is not reliable enough in some circumstances?

It's obvious - Send message directly to the control will garantee a success, it's a dircet interaction with the control :)

And via Send() keys can be sent to other window that is currently active (by user or other app).

  Quote

For example, when I make an input where I'm giving the user a typing facility by locating the caret at the 5th position, I'm using the Melba23 idea

You can do the same with GUICtrlSendMsg:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

$hWnd = GUICreate("Input with caret at desired position", 350, 130)
GUISetFont(14, 400, 1, "DOSLike")

$btnOK = GUICtrlCreateButton("&OK", 218, 70, 80, 30, 0)
GUICtrlCreateLabel("Number: ", 20, 24, 200, 20)
$input1 = GUICtrlCreateInput("555-123-456", 100, 22, 200, 24)

GUISetState()

GUICtrlSetState($input1, $GUI_FOCUS)
GUICtrlSendMsg($input1, $EM_SETSEL, 4, 4) ;first parameter (4) is the end of selection position, and the second is the start of selection position

While 1
    $nMsg = GUIGetMsg()
    
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $btnOK
            Exit
    EndSwitch
WEndoÝ÷ Ø    ÝnÜ0Ølzwr¢çhm綬y Þ-g¬Êjwhë-¶¬jëh×6Send("{Home}{Right 4}")

And one more thing; instead of Send you could use «ControlSend()», wich is also direct interaction with the control.

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

MrCreatoR,

Thank you for your understandable explanations, and for the remark in the line

GUICtrlSendMsg($input1, $EM_SETSEL, 4, 4) ;first parameter (4) is the end of selection position, and the second is the start of selection position

as well for the additions about {Right 4}.

I will try to use GUICtrlSendMsg() instead of Send() from now on.

As you perhaps have seen in my parallel posting http://www.autoitscript.com/forum/index.php?showtopic=95809 I still have a problem with Insert/Overwrite toggle method. Thanubis said there that it is not possible to get this behavior in a standard input field. Is there a workaround with GUICtrlSendMsg() or with a DLL call? Jos' example worked there because the SciTE Editor supports this toggle mode.

Beside that, I also need to know in which position the Ins/Ovw is toggled (result as a Boolean value).

And in an hour or three, I will post a new topic 'DOS alike Input Editor' with code that I was trying to write during the first days of this year... but abandoned because of typing problems. But it will show what I would like to obtain as a final Function.

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
  • Recently Browsing   0 members

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