Rendering Font Fixed Width
-
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?
-
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?
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.
-
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.
-
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?
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! -
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?
-
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!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 !!!
-
Doesn't
CFont font;
font.CreateStockObject(OEM_FIXED_FONT);
GetDlgItem(IDC_EDIT)->SetFont(&font);work?
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().
-
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().
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.