In a Edit Box, I could use "GetCaretPos()" to get the coordinate (x, y) of
the cursor, but how can I get the Text at the position?

In MFC, there is a funtion "CharFromPos()" to get the item, but there seems
has no corresponding function in Win32 API?

Any suggestion is appreciated

Y.C.

Re: Get Text from Cursor position by Frank

Frank
Fri Apr 28 07:41:05 CDT 2006

28.04.2006 13:06, Y.C. Wu schrob:

> In a Edit Box, I could use "GetCaretPos()" to get the coordinate (x, y) of
> the cursor, but how can I get the Text at the position?
>
> In MFC, there is a funtion "CharFromPos()" to get the item, but there seems
> has no corresponding function in Win32 API?

Basically, strings are arrays of characters, in the case of PPC this would
mean TCHAR.
So first get the text of the edit box into a TCHAR array and then simply
access its characters by using an index.

Example:

TCHAR szText[100];
SendMessage(WM_GETTEXT,hwndEdit,(WPARAM)100,(LPARAM)szText);

// get the 5th character
TCHAR c=szText[4];
--
Gruß | Greetings | Qapla'
http://www.stud.tu-ilmenau.de/~frst-ii/

Re: Get Text from Cursor position by r_z_aret

r_z_aret
Fri Apr 28 16:57:33 CDT 2006

On Fri, 28 Apr 2006 04:06:01 -0700, Y.C. Wu
<YCWu@discussions.microsoft.com> wrote:

>
>In a Edit Box, I could use "GetCaretPos()" to get the coordinate (x, y) of
>the cursor, but how can I get the Text at the position?
>
>In MFC, there is a funtion "CharFromPos()" to get the item, but there seems
>has no corresponding function in Win32 API?

MFC is just wrapper for Win32, so MFC can't do anything unless Win32
can do it first. We have access to much of the source code for MFC,
which is thus a decent "library" of code (not always easy to follow,
but definitely real and tested). However, I made a _quick_ attempt to
find source for CharFromPos and failed.

My next effort started by looking up GetCaretPos in my copy of MSDN
Library (AKA F1 help), then using "Locate", and then wandering to
"nearby" section for Edit boxes. That got me to EM_CHARFROMPOS.


>
>Any suggestion is appreciated
>
>Y.C.

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 478
Boston, MA 02116
www.penfact.com