Click here to Skip to main content
12,747,162 members (28,483 online)
Rate this:
Please Sign up or sign in to vote.
See more: VisualC++
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..


(Note: I have tried with GetSel,SetSel,GetCaretPos, SetCaretPos not solved my problem)
Posted 18-Aug-12 22:56pm
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.]
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.
Peter_in_2780 20-Aug-12 0:42am
My point was really about using a zero-length selection to set the cursor position. :)
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...


1 solution

Rate this: bad
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:[^].

See also this discussion:[^].

pasztorpisti 20-Aug-12 8:43am
5ed, Good answer.
Sergey Alexandrovich Kryukov 20-Aug-12 12:19pm
Thank you,

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 20 Aug 2012
Copyright © CodeProject, 1999-2017
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