Jump to content

Setting cursor pos inside input box


DickG
 Share

Recommended Posts

When I open a GUI that has an Input box, and the text for that box is long, the text has scrolled all the way to the right. I would like it to show the beginning of the text rather than the end. So I have to click inside the box and press Home to read the beginning.

Is there a way to do make it scroll left in the Input box?

Link to comment
Share on other sites

Maybe this thread helps

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

DickG,

Or perhaps like this:

#include <GUIConstantsEx.au3>

$sText = "A nice long string to get the input scrolled to the right"

$hGUI = GUICreate("Test", 500, 500)

$cInput = GUICtrlCreateInput($sText, 10, 10, 200, 20)

GUISetState()

ControlSend($hGUI, "", $cInput, "{HOME}")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

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

This Google search will return similar results.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Maybe this thread helps

Awesome! That works great! I could not find anything on this forum when I typed "cursor position input box". I was not aware of the _GUICtrlEdit_SetSel() command. I guess searching the AutoIt forums gives me better results from Google! :-)

Thanks much, water.

Link to comment
Share on other sites

Correct. At the moment Google gives the best search results as the forums search feature is awful since the last upgrade :(
Did you try the solution Melba provided? I think this is even more elegnat as it doesn't need to include a whole UDF.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

My idea:

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

AutoItSetOption("GUIOnEventMode", 1)

Global Const $hGUI = GUICreate("Test", 232, 90)
Global Const $iInput = GUICtrlCreateInput("", 42, 30, 140), $hInput = GUICtrlGetHandle($iInput)
Global Const $iButton = GUICtrlCreateButton("OK", 190, 50, 32, 32)
GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

While Sleep(100)
WEnd

Func _Exit()
    GUIDelete()
    Exit
EndFunc

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $iIDFrom = _WinAPI_LoWord($iwParam)
    Local $iCode = _WinAPI_HiWord($iwParam)
    Local $sInput, $aPosCtrl, $aPosWin
    Switch $ilParam
        Case $hInput
            Switch $iCode
                Case $EN_SETFOCUS
                    ControlClick($hGUI, "", $iInput, "", 1, 1)
                Case $EN_CHANGE
                    $sInput = GUICtrlRead($iInput)
                    If StringLen($sInput) > 22 Then
                        $aPosWin = WinGetPos($hGUI)
                        $aPosCtrl = ControlGetPos($hGUI, "", $iInput)
                        ToolTip($sInput, -100 + $aPosWin[0] + $aPosCtrl[0], $aPosWin[1] + $aPosCtrl[1])
                    EndIf
                Case $EN_KILLFOCUS
                    ToolTip("")
            EndSwitch
    EndSwitch
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_COMMAND

 

Edit: forget it, I got you wrong -> new year hangover :drinks:

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

DickG,

Or perhaps like this:

#include <GUIConstantsEx.au3>

$sText = "A nice long string to get the input scrolled to the right"

$hGUI = GUICreate("Test", 500, 500)

$cInput = GUICtrlCreateInput($sText, 10, 10, 200, 20)

GUISetState()

ControlSend($hGUI, "", $cInput, "{HOME}")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

M23

Thanks, Melba. I tried it, but couldn't get it to work. I must be doing something wrong because your sample does indeed work. But the _GUICtrlEdit_SetSel() command works for me, so I'll be using that.

Link to comment
Share on other sites

:)

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

$sText = "A nice long string to get the input scrolled to the right"

$hGUI = GUICreate("Test", 300, 100)
$cInput = GUICtrlCreateInput($sText, 10, 10, 200, 20)
GUISetState()
GuiCtrlSendMsg($cInput, $EM_SETSEL, 0, 0)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Link to comment
Share on other sites

:)

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

$sText = "A nice long string to get the input scrolled to the right"

$hGUI = GUICreate("Test", 300, 100)
$cInput = GUICtrlCreateInput($sText, 10, 10, 200, 20)
GUISetState()
GuiCtrlSendMsg($cInput, $EM_SETSEL, 0, 0)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Awesome!

GuiCtrlSendMsg($cInput, $EM_SETSEL, 0, 0) also works great! Now I have two great ways to do this!

Thanks much, mikell!

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