Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC++
Hi All!!
 
I'm Working on RichEdit Control, so when i paste the below code, cursor has to go directly to that location and write some text in rich edit control. So please suggest, and provide some sample code.
 
23H,10 CodeProject : Cursor has to go 23rd row and 10th column and need to write the text like shown.... In RichEdit Control.
 
Thanks in advance to all coders..
 
Regards
Sam
 
(Note: I have tried with GetSel,SetSel,GetCaretPos, SetCaretPos not solved my problem)
Posted 18-Aug-12 21:56pm
Comments
Richard MacCutchan at 19-Aug-12 5:16am
   
I am not sure that the RichEdit control has any concept of rows and columns. The text in the control is merely a stream of characters and is managed as such. You would need to calculate which character position exists at 23:10, which will vary according to the width and height of the control, and the font(s) used to display the text.
Peter_in_2780 at 20-Aug-12 0:23am
   
As Richard said, you will have to work out row/column for yourself. I'm not sure about RichEdit, but in other edit controls, the way to position the "cursor" (aka "insertion point") is to set a zero-length selection at the desired offset into the text buffer. AFAIK, Get/SetCaretPos are dealing in screen pixels position, which is not easily related to character offset in the text buffer.
[If this works, reply and I'll turn it into a solution.]
Sergey Alexandrovich Kryukov at 20-Aug-12 0:34am
   
You are right about pixel APIs, but direct row/column access is available in this control, only not so direct.
I've done it; and it works without counting each line in the application code.
Please see my solution.
--SA
Peter_in_2780 at 20-Aug-12 0:42am
   
My point was really about using a zero-length selection to set the cursor position. :)
Sergey Alexandrovich Kryukov at 20-Aug-12 1:10am
   
This is a correct point.
 
But the real problem is to locate line number by position and position by line. This could be done only by counting all lines, but the control itself keeps some internal data which helps to do it quickly by sending messages...
 
--SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It is all implemented in raw Windows API, but is accessible not through separate functions but through Windows messages. You can wrap sending appropriate messages with calculations into the functions you've listed. The messages are like EM_LINEFROMCHAR, EM_LINEINDEX and others. You will find them here:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb761611%28v=vs.85%29.aspx[^].
 
See also this discussion:
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/fc292bcc-ccaf-4ef4-bdf0-1480b0a9f492/[^].
 
—SA
  Permalink  
Comments
pasztorpisti at 20-Aug-12 8:43am
   
5ed, Good answer.
Sergey Alexandrovich Kryukov at 20-Aug-12 12:19pm
   
Thank you,
--SA

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 595
1 OriginalGriff 295
2 CPallini 210
3 PIEBALDconsult 150
4 Fredrik Bornander 140
0 OriginalGriff 5,835
1 Sergey Alexandrovich Kryukov 5,263
2 CPallini 4,750
3 George Jonsson 3,227
4 Gihan Liyanage 2,487


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 20 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100