Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Is there any WinAPI to get the selected text in an Edit Box? Take the initial and final position of the cursor? A function where I tell the HWND of editbox and the function return, the selected text?

Alexandre
Posted
Comments
[no name] 14-Jul-12 7:33am    
Why is this tagged C and Forms?
Alexandre Bencz 14-Jul-12 7:41am    
Because, Is in C.... I need this...

1 solution

First use

EM_GETSEL

to retrieve the character indices of the begin and end of the current selection.

For edit controls with small amounts of text you can use the window message
WM_GETTEXT to retrieve the entire window text and select the appropriate part of it.

For multi-line edit controls with huge amounts of text, this method can be inefficient. In that case you can use

EM_GETHANDLE

to get the memory handle of the buffer that the edit control uses. Use LocalLock to get a memory pointer to that buffer. Then you can access that buffer directly and retrieve the select text by using the character indices that EM_GETSEL has returned.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900