home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.misc
- Path: sparky!uunet!microsoft!hexnut!blakeco
- From: blakeco@microsoft.com (Blake Coverett)
- Subject: Re: Cursor location in edit control?
- Message-ID: <1992Sep02.014023.14502@microsoft.com>
- Date: 02 Sep 92 01:40:23 GMT
- Organization: Microsoft Canada Inc.
- References: <1992Sep1.104811.1@cortex>
- Lines: 22
-
- In article <1992Sep1.104811.1@cortex> mboucher@cortex.prospect.com (Mike Boucher) writes:
- >Is there a way, when you get a WM_CHAR message in an edit control, to determine
- >where the cursor is? I mean the location in the string, not the screen coords.
- >I need to know if the character is being appended to the end of the string,
- >tacked onto the front, or in the middle for validation purposes.
-
- I answered a closely related question by email just yesterday. Since this is
- the second along the same line (from a different person) I'll post this
- response.
-
- The easy way to remember this is to consider characters typed into an edit
- control as always replacing the current selection (which they do). The
- trick is that the selection is sometimes zero width, i.e. just the caret,
- resulting in the character being insert at that point.
-
- It is then obvious that you can use EM_SETSEL and EM_GETSEL to set and query
- the caret position just by making the end position equal to the start position.
-
- -Blake
- --
- #include <std/disclaimer.h> blakeco@microsoft.com
- Mail Flames, Post Apologies. ...!uunet!microsoft!blakeco
-