Home > Articles > Home & Office Computing > Microsoft Windows Desktop

The Secret Life of GetWindowText

  • Print
  • + Share This
GetWindowText is caught between rules, and therefore how it does its job is based on whether window classes are managing their text manually or letting the system do it. But why are things like this, and what if you don't like it? Raymond Chen describes the the history of this oft-maligned function.
This chapter is from the book

How windows manage their text

THERE ARE TWO ways window classes can manage their text. They can do it manually or they can let the system do it. The default is to let the system do it.

If a window class lets the system manage its text, the system will do the following:

  • Default handling of the WM_NCCREATE message takes the lpWindowName parameter passed to CreateWindow/Ex and saves the string in a “special place.”
  • Default handling of the WM_GETTEXT message retrieves the string from that special place.
  • Default handling of the WM_SETTEXT message copies the string to that special place.

On the other hand, if a window class manages its window text manually, the system does not do any special handling, and it is the window class’s responsibility to respond to the WM_GETTEXT/WM_SETTEXT messages and return/save the strings explicitly.

Frame windows typically let the system manage their window text. Custom controls typically manage their window text manually.

  • + Share This
  • 🔖 Save To Your Account