c++windowswinapieditboxcommon-controls

How to know offsets within EDIT control to draw text?


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


Solution

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

    SendMessage(hedit, EM_GETRECT, 0, (LPARAM)&rect)