Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
Richard MacCutchan 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 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 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 20-Aug-12 0:42am    
My point was really about using a zero-length selection to set the cursor position. :)
Sergey Alexandrovich Kryukov 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

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
 
Share this answer
 
Comments
pasztorpisti 20-Aug-12 8:43am    
5ed, Good answer.
Sergey Alexandrovich Kryukov 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)



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