Home > Software engineering >  CEdit redraw editing area, the size of error change after
CEdit redraw editing area, the size of error change after

Time:09-17

Redraw the editable area of edit box, but after the change of edit box size, ON_WM_NCCALCSIZE () there is no fire again, result in the edit box can't input; : ON_WM_NCPAINT () fire again, but the edit box area filling is flawed,
Void CCenterEdit: : OnNcCalcSize (BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR * LPNCSP)
{


//calculate the client area height men for a font
CFont * pFont=GetFont ();
CRect rectText;
RectText. SetRectEmpty ();

The CDC * pDC=GetDC ();

CFont * pOld=pDC - & gt; SelectObject (pFont);
PDC - & gt; DrawText (_T (" Ky "), rectText, DT_CALCRECT | DT_LEFT);
UINT uiVClientHeight=rectText. Height ();

PDC - & gt; SelectObject (pOld);
The ReleaseDC (pDC);

//calculate NC area to center text.

CRect rectWnd rectClient;
GetClientRect (rectClient);
GetWindowRect (rectWnd);

The ClientToScreen (rectClient);
Int I=GetDlgCtrlID ();
UINT uiCenterOffset=(rectClient Height () - uiVClientHeight)/2;
UINT uiCY=(rectWnd Height () - rectClient. Height ())/2;
UINT uiCX=(rectWnd Width () - rectClient. Width ())/2;

RectWnd. OffsetRect (- rectWnd. Left - rectWnd. Top);
M_rectNCTop=rectWnd;

M_rectNCTop. DeflateRect (uiCX uiCY, uiCX, uiCenterOffset + uiVClientHeight + uiCY);

M_rectNCBottom=rectWnd;

M_rectNCBottom. DeflateRect (uiCX, uiCenterOffset + uiVClientHeight + uiCY, uiCX, uiCY);

LPNCSP - & gt; RGRC [0]. Top +=uiCenterOffset;
LPNCSP - & gt; RGRC [0]. Bottom -=uiCenterOffset;

LPNCSP - & gt; RGRC [0]. Left +=uiCX;
LPNCSP - & gt; RGRC [0]. Right -=uiCY;
}
Void CCenterEdit: : OnNcPaint ()
{
The Default ();
CWindowDC dc (this);
CBrush Brush (RGB (6, 213, 226));


Dc. FillRect (m_rectNCBottom, & amp; Brush);
Dc. FillRect (m_rectNCTop, & amp; Brush);
}
CEdit unchanged size

CEdit change, can't edit, filled areas not all
  • Related