1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| // CEditCustom
IMPLEMENT_DYNAMIC(CEditCustom, CEdit)
CEditCustom::CEditCustom()
{
this->m_TopMargin = 0;
this->m_BottomMargin = 0;
}
CEditCustom::~CEditCustom()
{
}
BEGIN_MESSAGE_MAP(CEditCustom, CEdit)
ON_WM_NCCALCSIZE()
END_MESSAGE_MAP()
// CEditCustom message handlers
void CEditCustom::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
// TODO: Add your message handler code here and/or call default
this->UpdateMargins(lpncsp->rgrc[0]);
lpncsp->rgrc[0].top+=m_TopMargin;
lpncsp->rgrc[0].bottom-=m_BottomMargin;
}
void CEditCustom::UpdateMargins(CRect rect)
{
CClientDC dc(this);
CFont *pOldFont=dc.SelectObject(GetFont());
LONG TextHeight=dc.GetTextExtent(_T(" "),1).cy;
dc.SelectObject(pOldFont);
LONG delta=rect.Height()-TextHeight;
m_TopMargin=delta/2;
m_BottomMargin=delta-m_TopMargin;
} |