18

I find have used both these functions before, but I don't quite see the the difference between them. Well, I know that DrawText requires a formatting rectangle,and can do some text formatting, and textout only the starting coordinates, are there any other differences?

devjeetroy
  • 1,855
  • 6
  • 26
  • 43
  • unlink TextOut; DrawText has a format flags parameter which can control the behavior of output text, like DT_NOPREFIX that convert, for example, text = '&R' with output of '&R', where by default transform in mnemonic shortcut (underline R), when used to display buttons or labels controls. – antonio Oct 01 '19 at 08:59

3 Answers3

19

DrawText

  • It draws a text string into a rectangle region specified in logical coordinates.
  • It provides convenient ways of formatting multiline text.
  • It is mainly used for wordbreaking paragraph formatting, expanding tabs etc.

TextOut

  • It is a simple text-drawing function which is easy to use.
  • It draws a character string at a specified location, using the currently selected text attributes.
  • The text string to draw does not need to be zero terminated.

Also, take a look at ExtTextOut and DrawTextEx

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
cpx
  • 17,009
  • 20
  • 87
  • 142
  • 4
    In addition: DrawText respects kerning, while TextOut does not – BeyelerStudios Oct 13 '15 at 23:31
  • DrawText is useless, since he does not paint area not containing text. Leading to old text remaining on screen. And doing a background erase before calling DrawText will result in flicker on WinXp. I always had to just use ExtTextOut. – user13947194 Mar 20 '22 at 06:38
6

DrawText() is User32.dll

TextOut() is Gdi32.dll

DrawText most likely calls TextOut in its implementation.

Art K
  • 61
  • 1
  • 3
  • 1
    Yes, that is correct. `ExtTextOut` is generally faster. But [there are some edge cases](https://learn.microsoft.com/en-us/windows/desktop/gdi/drawing-text). – c00000fd Oct 27 '18 at 04:08
2

Draw text can be used to just give the length or size of text without actually displaying it. This is useful when you have to fine the maximum display length of a set of strings. Also if you supply a null terminated string as the input in DrawText, it is not necessary to supply the length of the string - that is automatically created.

Take a look at this and this.

Jan S
  • 1,831
  • 15
  • 21