Re: DrawText example, please
-
Hello! I have been having trouble understanding the function DrawText as defined in the MSDN Library: int DrawText(HDC hDC, LPCTSTR lpString, int nCount, LPRECT lpRect, UNIT uFormat); Can someone provide a simple example as to what this function does? Any help given me to better understand this function is appreciated. Mike
-
Hello! I have been having trouble understanding the function DrawText as defined in the MSDN Library: int DrawText(HDC hDC, LPCTSTR lpString, int nCount, LPRECT lpRect, UNIT uFormat); Can someone provide a simple example as to what this function does? Any help given me to better understand this function is appreciated. Mike
The first parameter is a device context. It's a handle to whatever you're drawing on. It could be the screen, a bitmap, printer, etc. The second parameter is the string you want to draw - no mystery there. The third parameter tells DrawText how much of the string it should draw - i.e., the length of the string. You can pass it -1, if you want it to draw the entire string. The fourth parameter is a bounding rectangle, in which the function will draw the text. The coordinates of the rectangle are in whatever units your device context is set to use. A screen device context would typically use pixels as coordinates. The last parameter tells DrawText how it should go about drawing the string. The DT_SINGLELINE flag specifies that the text should not be broken into several lines. DT_RIGHT would align the text to the right hand side of the bounding rectangle. DT_END_ELLIPSIS tells DrawText to draw "..." on the right hand side, in case the entire text does not fit in the bounding rectangle. These are just some of the flags that exist. I suggest you look at the MSDN documentation for more information. The flags can also be combined using the or operator. For instance: DT_RIGHT | DT_SINGLELINE would tell DrawText to draw the text on one line, and align it to the right.
-- The Show That Watches Back
-
Hello! I have been having trouble understanding the function DrawText as defined in the MSDN Library: int DrawText(HDC hDC, LPCTSTR lpString, int nCount, LPRECT lpRect, UNIT uFormat); Can someone provide a simple example as to what this function does? Any help given me to better understand this function is appreciated. Mike
Did you see DrawText on MSDN it has one example of it:)
WhiteSky