Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DrawText VS TextOut Win32

Tags:

c++

winapi

gdi

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?

like image 498
devjeetroy Avatar asked Nov 11 '11 05:11

devjeetroy


3 Answers

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

like image 196
cpx Avatar answered Oct 16 '22 05:10

cpx


DrawText() is User32.dll

TextOut() is Gdi32.dll

DrawText most likely calls TextOut in its implementation.

like image 30
Art K Avatar answered Oct 16 '22 04:10

Art K


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.

like image 2
Jan S Avatar answered Oct 16 '22 06:10

Jan S