Question

If I click inside a TRichEdit control, how can I get the Line index (I clicked on) from the mouse client coordinates?

In other words, how do I convert a client coordinate to a Line Index?

***EDIT I'm actually not clicking inside the TRichEdit control, I'm clicking in another control and need to synch with the TRichEdit control's line number.

Was it helpful?

Solution

Send EM_CHARFROMPOS and EM_LINEFROMCHAR messages to the RichEdit, eg:

POINTL pt = ...; // client coordinates
int pos = RichEdit1->Perform(EM_CHARFROMPOS, 0, (LPARAM)&pt);
int idx = RichEdit1->Perform(EM_LINEFROMCHAR, pos, 0);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top