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. CFontDialog

CFontDialog

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 3 Posters 2 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
    Try
    wrote on last edited by
    #1

    Hi All, I have created an application in which i can change the font attributes of a text. I am using CFontDialog to select font size, font family etc Before calling CFontDialog (while debugging) m_TextFont.m_cf.iPointSize is 140. (Font Size is 14). But when Font dialog is popped it is showing Font Size as 17. What may be the problem?

    D J 2 Replies Last reply
    0
    • T Try

      Hi All, I have created an application in which i can change the font attributes of a text. I am using CFontDialog to select font size, font family etc Before calling CFontDialog (while debugging) m_TextFont.m_cf.iPointSize is 140. (Font Size is 14). But when Font dialog is popped it is showing Font Size as 17. What may be the problem?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Care to share a code snippet with us?


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      1 Reply Last reply
      0
      • T Try

        Hi All, I have created an application in which i can change the font attributes of a text. I am using CFontDialog to select font size, font family etc Before calling CFontDialog (while debugging) m_TextFont.m_cf.iPointSize is 140. (Font Size is 14). But when Font dialog is popped it is showing Font Size as 17. What may be the problem?

        J Offline
        J Offline
        Jason Teagle
        wrote on last edited by
        #3

        I would hazard a guess to say that it is to do with how Windows maps fonts. In the LOGFONT structure, for example, it needs a *negative* value to get the full character height - a positive value gives a slightly different size as it doesn't check against the full character cell height. Now, this doesn't necessarily mean it's true in your case. I think we are going to need to see some sample code and / or an explanation of what you do as a user with the font dialogue in between examining those values - for example, do you simply cancel it, or do you choose something?

        T 1 Reply Last reply
        0
        • J Jason Teagle

          I would hazard a guess to say that it is to do with how Windows maps fonts. In the LOGFONT structure, for example, it needs a *negative* value to get the full character height - a positive value gives a slightly different size as it doesn't check against the full character cell height. Now, this doesn't necessarily mean it's true in your case. I think we are going to need to see some sample code and / or an explanation of what you do as a user with the font dialogue in between examining those values - for example, do you simply cancel it, or do you choose something?

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

          CFontDialog* m_TextFont = new CFontDialog(&lfFontAttr, CF_BOTH | CF_TTONLY | CF_INITTOLOGFONTSTRUCT);

          lfFontAttr is LOGFONT structure.

          m_TextFont->GetCurrentFont(&lfFontAttr);

          Here m_TextFont->m_cf.iPointSize is 140 (i got the value while debugging)

          if (m_TextFont->DoModal() == IDOK)
          {
          m_TextFont->GetCurrentFont(&lfFontAttr);
          -------
          }

          Font size 17 is shown in dialog.

          J 1 Reply Last reply
          0
          • T Try

            CFontDialog* m_TextFont = new CFontDialog(&lfFontAttr, CF_BOTH | CF_TTONLY | CF_INITTOLOGFONTSTRUCT);

            lfFontAttr is LOGFONT structure.

            m_TextFont->GetCurrentFont(&lfFontAttr);

            Here m_TextFont->m_cf.iPointSize is 140 (i got the value while debugging)

            if (m_TextFont->DoModal() == IDOK)
            {
            m_TextFont->GetCurrentFont(&lfFontAttr);
            -------
            }

            Font size 17 is shown in dialog.

            J Offline
            J Offline
            Jason Teagle
            wrote on last edited by
            #5

            My hunch was strangely accurate. If you look at the constructor for CFontDialog in MSDN, it has a sample (reproduced below) that sets a negative value (the pixel height) into lfHeight, not 1/10ths of a point as you have: // Show the font dialog with 12 point "Times New Roman" as the // selected font. LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); CClientDC dc(this); lf.lfHeight = -MulDiv(12, dc.GetDeviceCaps(LOGPIXELSY), 72); strcpy(lf.lfFaceName, "Times New Roman"); CFontDialog dlg(&lf); dlg.DoModal(); I believe this to be the source of the problem.

            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