Sign in to follow this  
Followers 0
jfcby

Edit Control Select Word [Resolved]

2 posts in this topic

#1 ·  Posted (edited)

Hi,

I'm trying to figure out how to select a word in an edit control.

I've looked in the help file at the:

1. PosFromChar and CharFromPos

2. SetSel, GetSel, and SetText

But with each of these you need the start character position and the end character position. I do not understand how to get them with the following code.

How do you get the character positions using this part of the code:

$array = StringRegExp(GUICtrlRead($Edit1), "[\s\.:;,]*([a-zA-Z0-9-_]+)[\s\.:;,]*", 3, $nOffset)

Full Code:

#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>

Global $msg

$hWidth = 395
$hHeight = 425
$hLeft = $hWidth / 2
$hTop = $hHeight / 2

$hGUI = GUICreate("Select Word In Edit Control Example", $hWidth, $hHeight, (@DesktopWidth / 2) - $hLeft, (@DesktopHeight / 2) - $hTop)

    $Label1 = GUICtrlCreateLabel("Editor", 5, 1, 100, 15)
    GUICtrlSetFont(-1, 9, 600)  
    
    $Edit1 = GUICtrlCreateEdit("Coutn adn splel", 5, 25, 385, 350, _
        BitOR($ES_AUTOVSCROLL, $ES_MULTILINE, $ES_NOHIDESEL, $ES_WANTRETURN))
    
    $Button1 = GUICtrlCreateButton("Select Word", 325, 380) 
    
GUISetState()

$nOffset = 1

While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit        
        Case $Msg = $Button1            
            _SelectWord()
    EndSelect
WEnd

Func _SelectWord()
    ;Select individual word.
    $array = StringRegExp(GUICtrlRead($Edit1), "[\s\.:;,]*([a-zA-Z0-9-_]+)[\s\.:;,]*", 3, $nOffset)
    
    If @error = 0 Then
        $nOffset = @extended
    Else
        ;ExitLoop
    EndIf
    
    For $i = 0 to UBound($array) - 1
        MsgBox(0, "RegExp Test with Option 1 - " & $i, $array[$i] & @CRLF)
        ConsoleWrite("RegExp Test with Option 1 - " & $i & " " & $array[$i] & @CRLF)
    Next
        
EndFunc     ;==>_SelectWord

Update 1/11/2010: For full example code go to: Xamp Spell Check

Edited by jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Share this post


Link to post
Share on other sites



Not sure if this is what you are after, but maybe it helps.

#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>

Global $msg

$hWidth = 395
$hHeight = 425
$hLeft = $hWidth / 2
$hTop = $hHeight / 2

$hGUI = GUICreate("Select Word In Edit Control Example", $hWidth, $hHeight, (@DesktopWidth / 2) - $hLeft, (@DesktopHeight / 2) - $hTop)

    $Label1 = GUICtrlCreateLabel("Editor", 5, 1, 100, 15)
    GUICtrlSetFont(-1, 9, 600)

    $Edit1 = GUICtrlCreateEdit("Coutn adn splel", 5, 25, 385, 350, _
    BitOR($ES_AUTOVSCROLL, $ES_MULTILINE, $ES_NOHIDESEL, $ES_WANTRETURN))

    $Button1 = GUICtrlCreateButton("Select Word", 325, 380)

GUISetState()

$nOffset = 1

While 1
    $Msg = GUIGetMsg()
    Select
    Case $Msg = $GUI_EVENT_CLOSE
    Exit
    Case $Msg = $Button1
    _SelectWord()
    EndSelect
WEnd

Func _SelectWord()
    ;Select individual word.
    $array = StringRegExp(GUICtrlRead($Edit1), "[\s\.:;,]*([a-zA-Z0-9-_]+)[\s\.:;,]*", 3, $nOffset)

    If @error = 0 Then
    $nOffset = @extended
    Else
    ;ExitLoop
    EndIf

    Local $sText = guictrlread($Edit1)
    Local $iTextLen = StringLen($sText)
    Local $from = 1;we search from here in edit text
    Local $ist;where we found the start of the word
    For $i = 0 to UBound($array) - 1
        $ist = stringinstr($sText,$array[$i],0,1,$from,$iTextLen) - 1
        $from = $ist + stringlen($array[$i])
        _GUICtrlEdit_SetSel($Edit1,$ist,$ist+stringlen($array[$i]))
        MsgBox(0, "RegExp Test with Option 1 - " & $i, $array[$i] & @CRLF)
    ConsoleWrite("RegExp Test with Option 1 - " & $i & " " & $array[$i] & @CRLF)
    Next

EndFunc     ;==>_SelectWord

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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