Sign in to follow this  
Followers 0
MattHiggs

(solved) Select a range of characters in an input control

3 posts in this topic

#1 ·  Posted (edited)

I wanted to know if it was possible to highlight a range of text in an input, similar to the functionality of _GUICtrlEdit_SetSel if I could use it on an input control.

Edited by MattHiggs

Share this post


Link to post
Share on other sites



An input control is an edit control, you can use SetSel on it

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

Example()

Func Example()
    Local $hStatusBar, $idEdit, $hGUI
    Local $sWow64 = ""
    If @AutoItX64 Then $sWow64 = "\Wow6432Node"
    Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt", "InstallDir") & "\include\_ReadMe_.txt"
    Local $aPartRightSide[3] = [190, 378, -1], $aSel

    ; Create GUI
    $hGUI = GUICreate("Edit Set Sel", 400, 300)
    $idEdit = GUICtrlCreateInput("", 2, 2, 394, 20)
    $hStatusBar = _GUICtrlStatusBar_Create($hGUI, $aPartRightSide)
    _GUICtrlStatusBar_SetIcon($hStatusBar, 2, 97, "shell32.dll")
    GUISetState(@SW_SHOW)

    ; Set Margins
    _GUICtrlEdit_SetMargins($idEdit, BitOR($EC_LEFTMARGIN, $EC_RIGHTMARGIN), 10, 10)

    ; Set Text
    _GUICtrlEdit_SetText($idEdit, FileRead($sFile))

    ; Set Sel
    _GUICtrlEdit_SetSel($idEdit, 15, 20)

    ; Get Sel
    $aSel = _GUICtrlEdit_GetSel($idEdit)
    _GUICtrlStatusBar_SetText($hStatusBar, "Start: " & $aSel[0])
    _GUICtrlStatusBar_SetText($hStatusBar, "End: " & $aSel[1], 1)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

 

1 person likes this

Share this post


Link to post
Share on other sites
19 hours ago, InunoTaishou said:

An input control is an edit control, you can use SetSel on it

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

Example()

Func Example()
    Local $hStatusBar, $idEdit, $hGUI
    Local $sWow64 = ""
    If @AutoItX64 Then $sWow64 = "\Wow6432Node"
    Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt", "InstallDir") & "\include\_ReadMe_.txt"
    Local $aPartRightSide[3] = [190, 378, -1], $aSel

    ; Create GUI
    $hGUI = GUICreate("Edit Set Sel", 400, 300)
    $idEdit = GUICtrlCreateInput("", 2, 2, 394, 20)
    $hStatusBar = _GUICtrlStatusBar_Create($hGUI, $aPartRightSide)
    _GUICtrlStatusBar_SetIcon($hStatusBar, 2, 97, "shell32.dll")
    GUISetState(@SW_SHOW)

    ; Set Margins
    _GUICtrlEdit_SetMargins($idEdit, BitOR($EC_LEFTMARGIN, $EC_RIGHTMARGIN), 10, 10)

    ; Set Text
    _GUICtrlEdit_SetText($idEdit, FileRead($sFile))

    ; Set Sel
    _GUICtrlEdit_SetSel($idEdit, 15, 20)

    ; Get Sel
    $aSel = _GUICtrlEdit_GetSel($idEdit)
    _GUICtrlStatusBar_SetText($hStatusBar, "Start: " & $aSel[0])
    _GUICtrlStatusBar_SetText($hStatusBar, "End: " & $aSel[1], 1)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

 

THank you for your reply.  I had a feeling that was the case.  I was trying to resolve a problem I was having with a script and thought that it was related to the subject of this post, but it wasn't.  Anyway, thanks for feedback.

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