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 font size - Need Help!!!!!

CFontDialog font size - Need Help!!!!!

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
3 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.
  • L Offline
    L Offline
    Lonnie Johnson
    wrote on last edited by
    #1

    In the OnBeginPrinting function of my view class I am displaying a CFontDialog dialog box. I want the default font to be Arial and the default size to be 8. When the dialog box displays, it a shows default size of 50. Here is the code. These are the first lines in the OnBeginPrinting function.

    ASSERT(pDC->GetMapMode() == MM_TEXT);
    LOGFONT lf;
    ::ZeroMemory(&lf, sizeof(LOGFONT));
    lf.lfHeight = -MulDiv(10, pDC->GetDeviceCaps(LOGPIXELSY), 72);
    lstrcpy(lf.lfFaceName, _T("Arial"));
    CFontDialog dlg(&lf, CF_PRINTERFONTS, pDC);
    if (dlg.DoModal() == IDOK)
    {
    m_strFont = dlg.GetFaceName();
    m_nPointSize = dlg.GetSize() / 10;
    }

    The value returned by pDC->GetDeviceCaps(LOGPIXELSY) is 600. The computed value for lf.lfHeight when 8 points is used is -67. The resulting size value in the Select Font dialog is 50. Why is the Select Font dialog displaying as font size of 50 instead of 8? Here are the results from some other point sizes. input dialog box 8 50 10 62 12 75 14 88 20 125 Every example of code I can find looks just like the above. Why is this code not working? Thanks!

    C L 2 Replies Last reply
    0
    • L Lonnie Johnson

      In the OnBeginPrinting function of my view class I am displaying a CFontDialog dialog box. I want the default font to be Arial and the default size to be 8. When the dialog box displays, it a shows default size of 50. Here is the code. These are the first lines in the OnBeginPrinting function.

      ASSERT(pDC->GetMapMode() == MM_TEXT);
      LOGFONT lf;
      ::ZeroMemory(&lf, sizeof(LOGFONT));
      lf.lfHeight = -MulDiv(10, pDC->GetDeviceCaps(LOGPIXELSY), 72);
      lstrcpy(lf.lfFaceName, _T("Arial"));
      CFontDialog dlg(&lf, CF_PRINTERFONTS, pDC);
      if (dlg.DoModal() == IDOK)
      {
      m_strFont = dlg.GetFaceName();
      m_nPointSize = dlg.GetSize() / 10;
      }

      The value returned by pDC->GetDeviceCaps(LOGPIXELSY) is 600. The computed value for lf.lfHeight when 8 points is used is -67. The resulting size value in the Select Font dialog is 50. Why is the Select Font dialog displaying as font size of 50 instead of 8? Here are the results from some other point sizes. input dialog box 8 50 10 62 12 75 14 88 20 125 Every example of code I can find looks just like the above. Why is this code not working? Thanks!

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Why do you think it is not working? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      1 Reply Last reply
      0
      • L Lonnie Johnson

        In the OnBeginPrinting function of my view class I am displaying a CFontDialog dialog box. I want the default font to be Arial and the default size to be 8. When the dialog box displays, it a shows default size of 50. Here is the code. These are the first lines in the OnBeginPrinting function.

        ASSERT(pDC->GetMapMode() == MM_TEXT);
        LOGFONT lf;
        ::ZeroMemory(&lf, sizeof(LOGFONT));
        lf.lfHeight = -MulDiv(10, pDC->GetDeviceCaps(LOGPIXELSY), 72);
        lstrcpy(lf.lfFaceName, _T("Arial"));
        CFontDialog dlg(&lf, CF_PRINTERFONTS, pDC);
        if (dlg.DoModal() == IDOK)
        {
        m_strFont = dlg.GetFaceName();
        m_nPointSize = dlg.GetSize() / 10;
        }

        The value returned by pDC->GetDeviceCaps(LOGPIXELSY) is 600. The computed value for lf.lfHeight when 8 points is used is -67. The resulting size value in the Select Font dialog is 50. Why is the Select Font dialog displaying as font size of 50 instead of 8? Here are the results from some other point sizes. input dialog box 8 50 10 62 12 75 14 88 20 125 Every example of code I can find looks just like the above. Why is this code not working? Thanks!

        L Offline
        L Offline
        Lonnie Johnson
        wrote on last edited by
        #3

        I have found the answer. lfHeight must be converted from print units to screen units because the CFontDialog class uses screen units. Here is the updated code:

        ASSERT(pDC->GetMapMode() == MM_TEXT);
        LOGFONT lf;
        ::ZeroMemory(&lf, sizeof(LOGFONT));
        int nPrintDpi = pDC->GetDeviceCaps(LOGPIXELSY);
        lf.lfHeight = -MulDiv(10, pDC->GetDeviceCaps(LOGPIXELSY), 72);

        // Convert lfHeight from print units to screen units
        // because the CFontDialog class uses Screen units
        HDC hDC = GetDC(m_pView->m_hWnd);
        int nScreenDpi = GetDeviceCaps(hDC, LOGPIXELSY);
        lf.lfHeight = MulDiv(lf.lfHeight, nScreenDpi, nPrintDpi);

        lstrcpy(lf.lfFaceName, _T("Arial"));
        CFontDialog dlg(&lf, CF_PRINTERFONTS, pDC);
        if (dlg.DoModal() == IDOK)
        {
        m_strFont = dlg.GetFaceName();
        m_nPointSize = dlg.GetSize() / 10;
        }

        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