First off, an edit-box is a UI item that allows the user to type text, but the sample strings you posted rather look like a status or result. Will the user have to type sth like "FAILED - SELF TEST"? I think you rather need a read-only control, like a static control (usually sunken, etched or static edge style), as @Barmak Shemirani suggested.
In any case, I would recommend the following:
- First, consider enlarging the control instead, if there is space. Normally, all controls on a dialog use the same font (and this is by default). Having some controls using a different font may look weird (albeit possibly acceptable).
- Second (if you wouldn't enlarge the control), experiment with the font size, before attempting to programmatically set the font size: set the text to FAILED - SELF TEST (longest), and "manually" set the font size to the largest possible (so that the text fits) and see if you get an acceptable result.
If so, you can programmatically set the font size. MFC is to some degree a "thin wrapper" of WinAPI, and all WinAPI items are accesible as public members of the MFC classes (eg m_hWnd
is the handle of the WinAPI window of any CWnd
-derived class), so you rather work at WinAPI level here. You should check/set the font size during initialization (WM_INITDIALOG
message, mapped to the OnInitDialog()
handler). These are the steps:
- Check if the (default) font is OK: use the
DrawText()
function with the DT_CALCRECT
flag set. This won't actually draw any text, instead it will return the size (rectangle) needed. Add some margin too (pls experiment, but it should be at least 4 pixels - two vertical lines for the frame and 1 pixel at each side). If this is less than or eaual to the control's size (alternatively you can test with the text width with no extra margin vs the control's client area, not total size), this means that the default font is OK, and no other action needed.
- If not, get the control's font, and create a new font with the same parameters except for the size, which should be reduced by 1 (beware of the
lfHeight
parameter or member, if it's negative it should be instead "increased"). Check if with this font is OK now, and if not repeat this step until the text fits.
- I wouldn't recommend trying to increase the font size, as this would require testing against the control's height as well, but if you are willing to...
Hope this helps, although I don't know if it's worth the effort.