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. Getting the rect of the text in a Static

Getting the rect of the text in a Static

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 4 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.
  • T Offline
    T Offline
    Tommy2k
    wrote on last edited by
    #1

    Is there any good way to do this or do I know a workaround of some sort?

    B V 2 Replies Last reply
    0
    • T Tommy2k

      Is there any good way to do this or do I know a workaround of some sort?

      B Offline
      B Offline
      basementman
      wrote on last edited by
      #2

      To get the rect of the control or of the text itself? // Control: CRect oR; CWnd *pStatic = GetDlgItem(IDC_THE_STATIC_CTRL); pStatic->GetWindowRect(&oR); ScreenToClient(&oR); // bounding rectangle of static's text contents CString cText; GetDlgItemText(IDC_THE_STATIC_CTRL,cText); CWnd *pStatic = GetDlgItem(IDC_THE_STATIC_CTRL); pStatic->GetClientRect(&oR); CDC *pDC = pStatic->GetDC(); pDC->DrawText(cText,&oR,DT_CALCRECT|DT_LEFT|DT_SINGLELINE|DT_TOP); pStatic->ReleaseDC(pDC); // oR now has the bounding rectangle needed to display the text.  onwards and upwards...

      T 1 Reply Last reply
      0
      • T Tommy2k

        Is there any good way to do this or do I know a workaround of some sort?

        V Offline
        V Offline
        valikac
        wrote on last edited by
        #3

        One solution is to get the rect of the entire edit windows and then use GetTextExtent() to take add and subtract unit size. Kuphryn

        1 Reply Last reply
        0
        • B basementman

          To get the rect of the control or of the text itself? // Control: CRect oR; CWnd *pStatic = GetDlgItem(IDC_THE_STATIC_CTRL); pStatic->GetWindowRect(&oR); ScreenToClient(&oR); // bounding rectangle of static's text contents CString cText; GetDlgItemText(IDC_THE_STATIC_CTRL,cText); CWnd *pStatic = GetDlgItem(IDC_THE_STATIC_CTRL); pStatic->GetClientRect(&oR); CDC *pDC = pStatic->GetDC(); pDC->DrawText(cText,&oR,DT_CALCRECT|DT_LEFT|DT_SINGLELINE|DT_TOP); pStatic->ReleaseDC(pDC); // oR now has the bounding rectangle needed to display the text.  onwards and upwards...

          T Offline
          T Offline
          Tommy2k
          wrote on last edited by
          #4

          Wouldn't it be better to just make a memDC so the text itself won't show up on the control (it's already there ofcourse)? Or doesn't it do this anyway?

          J 1 Reply Last reply
          0
          • T Tommy2k

            Wouldn't it be better to just make a memDC so the text itself won't show up on the control (it's already there ofcourse)? Or doesn't it do this anyway?

            J Offline
            J Offline
            John M Drescher
            wrote on last edited by
            #5

            With the DT_CALCRECT the drawtext does not go to the screen it just calculates the rect. John

            T 1 Reply Last reply
            0
            • J John M Drescher

              With the DT_CALCRECT the drawtext does not go to the screen it just calculates the rect. John

              T Offline
              T Offline
              Tommy2k
              wrote on last edited by
              #6

              :-) Great! Thnx

              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