home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / mswindo / programm / misc / 1634 < prev    next >
Encoding:
Text File  |  1992-09-01  |  1.5 KB  |  33 lines

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