Jump to content

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


Recommended Posts

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

 

Link to comment
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.

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