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. Rendering Font Fixed Width

Rendering Font Fixed Width

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialhelpquestion
8 Posts 5 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
    MJ_Karas
    wrote on last edited by
    #1

    Can anyone provide me information on how to render the font in a dialog edit box in a fixed pitch format as opposed to the normal way that the font normally displays. For example the normal Dialog font is MS San Serif and this is a font with variable width characters and is normally rendered in a variable pitch manner. I need to render the font in a fixed pitch format so that columns of text in edit boxes stacked above one another will line up vertically. I have tried using the Trur Type Courier font....That works until one switches the dialog font to unicode in order to support Japanese, Chinese, Arabic, etc. ANy help out there?

    P P N 3 Replies Last reply
    0
    • M MJ_Karas

      Can anyone provide me information on how to render the font in a dialog edit box in a fixed pitch format as opposed to the normal way that the font normally displays. For example the normal Dialog font is MS San Serif and this is a font with variable width characters and is normally rendered in a variable pitch manner. I need to render the font in a fixed pitch format so that columns of text in edit boxes stacked above one another will line up vertically. I have tried using the Trur Type Courier font....That works until one switches the dialog font to unicode in order to support Japanese, Chinese, Arabic, etc. ANy help out there?

      P Offline
      P Offline
      Prem Kumar
      wrote on last edited by
      #2

      I dont think you can do that. But what I would suggest is go for GetTextExtent and test the width and keep adding spaces until you get enough for the column width you want to have.

      M 1 Reply Last reply
      0
      • P Prem Kumar

        I dont think you can do that. But what I would suggest is go for GetTextExtent and test the width and keep adding spaces until you get enough for the column width you want to have.

        M Offline
        M Offline
        MJ_Karas
        wrote on last edited by
        #3

        Thanks Prem.....But I need individual character columns to line up vertically just as they would with a fixed pitch font.:)

        1 Reply Last reply
        0
        • M MJ_Karas

          Can anyone provide me information on how to render the font in a dialog edit box in a fixed pitch format as opposed to the normal way that the font normally displays. For example the normal Dialog font is MS San Serif and this is a font with variable width characters and is normally rendered in a variable pitch manner. I need to render the font in a fixed pitch format so that columns of text in edit boxes stacked above one another will line up vertically. I have tried using the Trur Type Courier font....That works until one switches the dialog font to unicode in order to support Japanese, Chinese, Arabic, etc. ANy help out there?

          P Offline
          P Offline
          Paul M Watt
          wrote on last edited by
          #4

          I think in order to do this with a TTF that is not mono-spaced you will need to create an owner-drawn version of the edit control. When you draw the characters, you will first need to scan the font that you are creating and determine the width of the largest character in the font. You can use a function like GetCharWidth32. Then when you paint your characters into the edit control, the column width will be at least the width that you calculated for the widest character. You will need to paint one character at a time, one character per column.


          Build a man a fire, and he will be warm for a day
          Light a man on fire, and he will be warm for the rest of his life!

          M 1 Reply Last reply
          0
          • M MJ_Karas

            Can anyone provide me information on how to render the font in a dialog edit box in a fixed pitch format as opposed to the normal way that the font normally displays. For example the normal Dialog font is MS San Serif and this is a font with variable width characters and is normally rendered in a variable pitch manner. I need to render the font in a fixed pitch format so that columns of text in edit boxes stacked above one another will line up vertically. I have tried using the Trur Type Courier font....That works until one switches the dialog font to unicode in order to support Japanese, Chinese, Arabic, etc. ANy help out there?

            N Offline
            N Offline
            Niklas L
            wrote on last edited by
            #5

            Doesn't

            CFont font;
            font.CreateStockObject(OEM_FIXED_FONT);
            GetDlgItem(IDC_EDIT)->SetFont(&font);

            work?

            M 1 Reply Last reply
            0
            • P Paul M Watt

              I think in order to do this with a TTF that is not mono-spaced you will need to create an owner-drawn version of the edit control. When you draw the characters, you will first need to scan the font that you are creating and determine the width of the largest character in the font. You can use a function like GetCharWidth32. Then when you paint your characters into the edit control, the column width will be at least the width that you calculated for the widest character. You will need to paint one character at a time, one character per column.


              Build a man a fire, and he will be warm for a day
              Light a man on fire, and he will be warm for the rest of his life!

              M Offline
              M Offline
              MJ_Karas
              wrote on last edited by
              #6

              Thanks....your suggestion appears to be exactly what must be done. I have looked at the GetCharWidth32() function and it gives exactly the information I need. I think I may just scan the strings I am trying to display at the given moment and find the widest character from that set and align the multiple stacked edit boxes based upon that width. If the user edits the string(s) again and selects some other wider character the controls repaint anyway and will find the wider character and update accordingly. Thanks Again !!!

              1 Reply Last reply
              0
              • N Niklas L

                Doesn't

                CFont font;
                font.CreateStockObject(OEM_FIXED_FONT);
                GetDlgItem(IDC_EDIT)->SetFont(&font);

                work?

                M Offline
                M Offline
                MJ_Karas
                wrote on last edited by
                #7

                I believe that your suggestion will give a result that is similar to my current use of the Courier font. I actually need to find the solution that works with the font that is already set for the dialog. This is becasue that font may have been set to a Unicode font with far eastern characters in it and I need to make sure that font gets used, not one selected by the CreateStockObject().

                M 1 Reply Last reply
                0
                • M MJ_Karas

                  I believe that your suggestion will give a result that is similar to my current use of the Courier font. I actually need to find the solution that works with the font that is already set for the dialog. This is becasue that font may have been set to a Unicode font with far eastern characters in it and I need to make sure that font gets used, not one selected by the CreateStockObject().

                  M Offline
                  M Offline
                  Mike Nordell
                  wrote on last edited by
                  #8

                  My question is: Do you really need it to be a multi-line edit? Perhaps a simple listbox where you set tab stops would do it, or even a list control? After all, if you want to display columnar data it seems a list control indeed is what you are looking for.

                  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