2

I have a richedit containing lines using different fonts, styles, languages etc.

I am drawing in a gutter. I would like to start my drawing at the same y pixel position as the corresponding line.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tom
  • 3,587
  • 9
  • 69
  • 124

1 Answers1

5

Send the control an em_PosFromChar message. It returns the client coordinates of the character at the given index, although the documentation doesn't say what the coordinates represent (upper left corner, baseline center, or what). You're looking for the character's baseline.

Use em_LineIndex to get a character index for a given line number, if you don't already know the index of a character you're interested in.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
  • +1. I looked, and this message wasn't listed in the [docs for the RichEdit](http://msdn.microsoft.com/en-us/library/bb787605%28VS.85%29.aspx) on MSDN, but a Google search turned up a link to it there (the one you posted, BTW). (I thought I remembered something like it, but couldn't quite come up with the message name, and figured I'd remembered wrong when I couldn't find it in the docs.) :-) – Ken White Dec 23 '12 at 07:07
  • Thanks! It works :) Example code: char_idx := Perform(EM_LINEINDEX, line_idx, 0); Perform(EM_POSFROMCHAR, WPARAM(@char_pt), char_idx); ARect.Top := char_pt.y; ARect.Bottom := ARect.Top + letter_height; – Tom Dec 24 '12 at 00:07