CEdit重绘垂直居中显示
来源:互联网 发布:切片软件 编辑:程序博客网 时间:2024/05/17 06:23
原文:http://stackoverflow.com/questions/867207/how-can-we-vertically-align-text-in-edit-box
/// HEADER //////////////////////////////////////////
class CEditVC : public CEdit
{
public:
CEditVC();
protected:
CRect m_rectNCBottom;
CRect m_rectNCTop;
public:
virtual ~CEditVC();
protected:
afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp);
afx_msg void OnNcPaint();
afx_msg UINT OnGetDlgCode();
DECLARE_MESSAGE_MAP()
};
/// IMPLEMENTATION /////////////////////////////////////////
CEditVC::CEditVC()
: m_rectNCBottom(0, 0, 0, 0)
, m_rectNCTop(0, 0, 0, 0)
{
}
CEditVC::~CEditVC()
{
}
BEGIN_MESSAGE_MAP(CEditVC, CEdit)
ON_WM_NCCALCSIZE()
ON_WM_NCPAINT()
ON_WM_GETDLGCODE()
END_MESSAGE_MAP()
void CEditVC::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
{
CRect rectWnd, rectClient;
//calculate client area height needed for a font
CFont *pFont = GetFont();
CRect rectText;
rectText.SetRectEmpty();
CDC *pDC = GetDC();
CFont *pOld = pDC->SelectObject(pFont);
pDC->DrawText("Ky", rectText, DT_CALCRECT | DT_LEFT);
UINT uiVClientHeight = rectText.Height();
pDC->SelectObject(pOld);
ReleaseDC(pDC);
//calculate NC area to center text.
GetClientRect(rectClient);
GetWindowRect(rectWnd);
ClientToScreen(rectClient);
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->rgrc[0].top +=uiCenterOffset;
lpncsp->rgrc[0].bottom -= uiCenterOffset;
lpncsp->rgrc[0].left +=uiCX;
lpncsp->rgrc[0].right -= uiCY;
}
void CEditVC::OnNcPaint()
{
Default();
CWindowDC dc(this);
CBrush Brush(GetSysColor(COLOR_WINDOW));
dc.FillRect(m_rectNCBottom, &Brush);
dc.FillRect(m_rectNCTop, &Brush);
}
UINT CEditVC::OnGetDlgCode()
{
if(m_rectNCTop.IsRectEmpty())
{
SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED);
}
return CEdit::OnGetDlgCode();
}
- CEdit重绘垂直居中显示
- CEdit 单行垂直居中显示
- CEdit 垂直居中
- CEdit文本上下居中(垂直居中)
- CEdit 文本垂直居中(单行解决方案)
- 【MFC】单行CEdit文本的“垂直居中”
- div垂直居中显示
- 垂直居中显示
- CEdit 重绘
- MFC CEdit重绘
- div水平垂直居中显示
- DIV水平垂直居中显示
- Web_CSS_DIV内部垂直居中显示
- UITextView 单行垂直居中显示
- 图片左右垂直居中显示
- div+css垂直居中显示
- VCenterEdit一个比较完美的文本垂直居中的CEdit类(和改进)
- Vertical Text Centering in an Edit Control(CEdit 单行 垂直居中)
- EasyGame网络游戏服务器解决方案
- 什么是“以管理员身份运行”
- JVM方法内联
- POJ 2796 Feel Good (单调栈)
- Web service是什么?
- CEdit重绘垂直居中显示
- C语言经典算法100例-016-求最大公约数和最小公倍数
- Linux 第一课 学习的方向
- synchronized详解
- 计算几何三维模板
- 数据结构 -- 查找之 二分法查找
- 如何在ElementaryOS(Ubuntu 12.10)上搞定娇羞的Lumia920(Win8 phone)
- 树百业2014第十届广州国际汽车改装服务业展览会
- 《高效学习OpenGL》 之 裁剪测试 alpha测试 glScissor(),glAlphaFunc()