2

I'm subclassing the EDIT common control to add some special placeholder text behavior in the background and I'm curious how to know offsets to draw text within in?

h and w in this diagram:

enter image description here

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • Why not just call `SetWindowText`? – Richard Critten Jun 10 '16 at 07:01
  • 2
    You can get that from `SendMessage(hedit, EM_GETRECT, 0, (LPARAM)&rect)` The way you have marked it, some of the gap is from the font itself, but you don't have to worry about that. – Barmak Shemirani Jun 10 '16 at 07:02
  • 1
    Maybe this isn't the case, but if you are about to reinvent another wheel, make sure to have a look at [EM_SETCUEBANNER](https://msdn.microsoft.com/en-us/library/windows/desktop/bb761639.aspx), and see if that doesn't suffice for your purposes. – IInspectable Jun 10 '16 at 07:21
  • @IInspectable: EM_SETCUEBANNER does not work on XP (or it is buggy, I should say.) – c00000fd Jun 10 '16 at 07:22
  • @BarmakShemirani: Thank you. It did the job! I wasn't aware that such message existed. Btw, you might want to post it as a separate answer and I'll mark it. – c00000fd Jun 10 '16 at 07:23

1 Answers1

3

Use EM_GETRECT to get the formatting rectangle for edit control. For example:

SendMessage(hedit, EM_GETRECT, 0, (LPARAM)&rect)
Barmak Shemirani
  • 30,904
  • 6
  • 40
  • 77