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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Text Size in a CStatic Control

Text Size in a CStatic Control

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 2 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.
  • D Offline
    D Offline
    David Viggiano
    wrote on last edited by
    #1

    Does anyone know of a way to get the dialog units for the text in a CStatic control? I'm trying to dynamically resize some controls and what MSDN says to do seems to always return 25-50% too big. Here is what I am trying: CDC *pDC; CSize cStringSize; pDC = m_MyStaticControl.GetWindowDC(); cStringSize = pDC->GetTextExtent ("Some string I want the size of..."); I've also tried DrawText(...) but that returns the same size. Thanks for the help, David

    T 1 Reply Last reply
    0
    • D David Viggiano

      Does anyone know of a way to get the dialog units for the text in a CStatic control? I'm trying to dynamically resize some controls and what MSDN says to do seems to always return 25-50% too big. Here is what I am trying: CDC *pDC; CSize cStringSize; pDC = m_MyStaticControl.GetWindowDC(); cStringSize = pDC->GetTextExtent ("Some string I want the size of..."); I've also tried DrawText(...) but that returns the same size. Thanks for the help, David

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      You need to select the right font into DC first. Default font is larger than the one used by your control. As a little OT note, you should also use CWindowDC or CClientDC instead of GetWindowDC call. Tomasz Sowinski -- http://www.shooltz.com

      *** Vodka. Connecting people. ***

      D 1 Reply Last reply
      0
      • T Tomasz Sowinski

        You need to select the right font into DC first. Default font is larger than the one used by your control. As a little OT note, you should also use CWindowDC or CClientDC instead of GetWindowDC call. Tomasz Sowinski -- http://www.shooltz.com

        *** Vodka. Connecting people. ***

        D Offline
        D Offline
        David Viggiano
        wrote on last edited by
        #3

        Tomasz, Great! Thanks for the help, that did the trick. One more question, how do I figure out what font the CStatic is going to use? I ended creating a different font first (looks better anyway). Thanks again, David

        T 1 Reply Last reply
        0
        • D David Viggiano

          Tomasz, Great! Thanks for the help, that did the trick. One more question, how do I figure out what font the CStatic is going to use? I ended creating a different font first (looks better anyway). Thanks again, David

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          CWnd::GetFont does the trick. Tomasz Sowinski -- http://www.shooltz.com

          *** Vodka. Connecting people. ***

          D 1 Reply Last reply
          0
          • T Tomasz Sowinski

            CWnd::GetFont does the trick. Tomasz Sowinski -- http://www.shooltz.com

            *** Vodka. Connecting people. ***

            D Offline
            D Offline
            David Viggiano
            wrote on last edited by
            #5

            Simple, thanks yet again.

            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