void CMyEdit::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CEdit::OnPaint() for painting messages
CRect rect;
GetWindowRect(rect);
CRect rect2 = rect;
rect2.left += 1;
rect2.right -= 1;
rect2.top += 1;
rect2.bottom -= 1;
ScreenToClient(rect);
ScreenToClient(rect2);
//CPen pen(PS_SOLID, 2, RGB(255,0,0));
//CPen * pOldPen = dc.SelectObject(&pen);
dc.Draw3dRect(rect, RGB(255, 0, 0), RGB(255, 0, 0));
dc.Draw3dRect(rect2, RGB(255, 0, 0), RGB(255, 0, 0));
Invalidate();
Default();
//dc.SelectObject(pOldPen);
}
如果你想要手动创建这样的窗口,可以用如下的方法:
m_myEdit.CreateEx(WS_EX_CLIENTEDGE, _T("EDIT"), NULL, WS_CHILD|WS_VISIBLE|ES_LEFT, CRect(40,40,140,140), this, 0);
注意:不要加WS_BORDER风格
原理介绍:
-
WS_EX_CLIENTEDGE Specifies that a window has a 3D look — that is, a border with a sunken edge.
CreateEx时窗口大小为100,100。倘若加上WS_EX_CLIENTEDGE则窗口客户区为96,96,
我们就是自己重新绘制了这被削减的四个方向上的边框。