Jump to content

How to get selected text from edit control


E1M1
 Share

Recommended Posts

How do I get selected text from edit control?I have GUI with edit control, and I select some some text there. Now I want get that selected text, how could I do it?

I have gui that is similar to window's notepad, but I cant find code for "copy" button only code I invent was send("^c") , but I need other than send.

edited

Link to comment
Share on other sites

_GUICtrlEdit_GetSel().

Return Value

Success: Array in the following format:

[0] - Starting position

[1] - Ending position

It return position but I want get text, then I still need function to get all char(s) from $pos[0] to $pos[1]

edited

Link to comment
Share on other sites

It return position but I want get text, then I still need function to get all char(s) from $pos[0] to $pos[1]

If you know the first position and the last then there's not muchmore to figure out.

$range = _GUICtrlEdit_GetSel(GUICtrlGetHandle($Edit1))
If $range[0] <> $range[1] Then
  $SelectedText = StringMid(GUICtrlRead($Edit1), $range[0] + 1, $range[1] - $range[0]))
EndIf

Or something pretty close to that.

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.
Link to comment
Share on other sites

  • 6 years later...

Hello,

sorry for take back this post. I used MVPs code:

$range = _GUICtrlEdit_GetSel(GUICtrlGetHandle($Edit1))
 

$range = _GUICtrlEdit_GetSel(GUICtrlGetHandle($Edit1))
If $range[0] <> $range[1] Then
  $SelectedText = StringMid(GUICtrlRead($Edit1), $range[0] + 1, $range[1] - $range[0]))
EndIf

this works perfectly to obtain selected text. Now, how replace text in same position ?

eg:

- i select letter Y form : New York

- recover selection with above code

- replace selection in that point with different letter : New Zork

 

thank you,

m.

Link to comment
Share on other sites

This is a 6 year old topic, my suggestion would have been to start a new topic.

But, just use the function :

_GUICtrlEdit_ReplaceSel(GUIctrlGetHandle($Edit1), "Z")

instead.

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Glad it helped. 

For next time. ;)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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