Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Re: DrawText example, please

Re: DrawText example, please

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mla154
    wrote on last edited by
    #1

    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

    J H 2 Replies Last reply
    0
    • M mla154

      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

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • M mla154

        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

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        Did you see DrawText on MSDN it has one example of it:)


        WhiteSky


        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups