15,980
社区成员




m_Edit.SetWindowText("1234567890");
m_Edit2.SetWindowText("1234567890");
m_Edit3.SetWindowText("1234567890");
m_Edit4.SetWindowText("1234567890");
m_Edit.SetFont(&m_font);
m_Edit2.SetFont(&m_font);
m_Edit3.SetFont(&m_font);
m_Edit4.SetFont(&m_font);
SetEdtTextCenter2(&m_Edit);
SetEdtTextCenter2(&m_Edit2);
SetEdtTextCenter2(&m_Edit3);
SetEdtTextCenter2(&m_Edit4);
void CEdtDlg::SetEdtTextCenter2(CEdit* pEdit)
{
CRect rc;
pEdit->GetClientRect(&rc);
CDC* pDC=pEdit->GetDC();
TEXTMETRIC _tm;
pDC->GetTextMetrics(&_tm);
int _nFontHeight =_tm.tmHeight +_tm.tmExternalLeading;
int _nMargin = (rc.Height() -_nFontHeight)/2;
rc.DeflateRect(0,_nMargin);
pEdit->SetRectNP(&rc);
}
void CVertCenterEdit::SetEditVertCenter()
{
CRect rc;
GetClientRect(&rc);
CDC* pDC=GetDC();
HGDIOBJ hOld = pDC->SelectObject(&m_FontVertEdit);
//
// TEXTMETRIC _tm;
// pDC->GetTextMetrics(&_tm);
// int _nFontHeight =_tm.tmHeight +_tm.tmExternalLeading;
//
SIZE size;
GetTextExtentPoint32W (pDC->m_hDC, L"f", 1, &size) ;
int nFontHeight =size.cy;
pDC->SelectObject(hOld);
//
int nMargin = (rc.Height() - nFontHeight)/2;
rc.DeflateRect(0, nMargin);
SetRect(&rc);
}
void CVertCenterEdit::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
m_FontVertEdit.CreateFont(32, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE
, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY
, VARIABLE_PITCH | FF_SWISS, TEXT("SANS SERIF"));
SetFont(&m_FontVertEdit);
SetEditVertCenter();
CEdit::PreSubclassWindow();
}