set height of output window

hi,
I have an output window in my application, based on an CEdit object. (with multiline style)
I set its height to contain 2 lines(if working on small fonts).
The problem is that when working in large fonts I can see only a little bit more than one line.
how can I calculate the height which I need to set the CEdit Ctrl, in a way that it will contain 2 lines both in small and large fonts ??

Yoav.
yoavoAsked:
Who is Participating?
 
Vinayak KumbarConnect With a Mentor Sr Program ManagerCommented:
Hi,

This should solve Ur problem

TEXTMETRIC txtmat;      
CRect rect;
CFont *font = this->GetFont();

CClientDC dc(this);
dc.SelectObject(font);
dc.GetTextMetrics(&txtmat);
      
m_ctrlFontEdit.GetWindowRect(&rect);
ScreenToClient(&rect);
      m_ctrlFontEdit.SetWindowPos(&m_ctrlFontEdit.wndTop,10,10, 100, (txtmat.tmHeight + txtmat.tmExternalLeading)*2, SWP_SHOWWINDOW);

Hope this helps.
VinExpert
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

If U can get the font type(small or large), then using that calculate the height(may be it will be constant), then set the hieght of the edit control using the MoveWindow() function.

((CEdit *)GetDlgItem(ID_EDIT1))->MoveWindow(...);

Try it out.

VinExpert
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

Just try by putting this code in the OnIntitDialog for that dialog.
TEXTMETRIC txtmat;      
CRect rect;
CClientDC dc(this);
dc.GetTextMetrics(&txtmat);
      
m_ctrlFontEdit.GetWindowRect(&rect);
ScreenToClient(&rect);
      m_ctrlFontEdit.SetWindowPos(&m_ctrlFontEdit.wndTop,10,10, 100, txtmat.tmHeight*2, SWP_SHOWWINDOW);

Here m_ctrlFontEdit in the control variable to that edit control.

Try it out.
VinExpert
0
 
captainkirkCommented:
Actually, use txtmat.tmHeight + txtmat.tmExternalLeading to get the height of your line...
0
All Courses

From novice to tech pro — start learning today.