编辑框等控件边框美化

源码说明:美化能获取焦点控件的边框颜色,获取焦点后颜色不同(类似彗星小助手、QQ等软件),支持自定义颜色,支持单独设置各个控件颜色.
实现方法:子类化,在WM_NCPAINT、WM_PAINT等消息自己画出边框
开发环境:VS2005 MFC / 易语言
源码下载:http://download.csdn.net/detail/cometnet/5663673



// SkinEdit.cpp : 实现文件
//

#include "stdafx.h"
#include "SkinEdit.h"


// CSkinEdit

IMPLEMENT_DYNAMIC(CSkinEdit, CEdit)

CSkinEdit::CSkinEdit()
{
	m_bTracking=m_bHover=m_bFocus=FALSE;
	m_ClientBrush=::CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
	m_hOrderBrush=::CreateSolidBrush(GetSysColor(COLOR_WINDOWFRAME));
	m_HotOrderBrush1=::CreateSolidBrush(0xFDC860);
	m_HotOrderBrush2=::CreateSolidBrush(0xE7AC49);
}

CSkinEdit::~CSkinEdit()
{
	DeleteObject(m_ClientBrush);
	DeleteObject(m_hOrderBrush);
	DeleteObject(m_HotOrderBrush1);
	DeleteObject(m_HotOrderBrush2);
}


BEGIN_MESSAGE_MAP(CSkinEdit, CEdit)
	ON_WM_NCPAINT()
	ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
	ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)
	ON_WM_MOUSEMOVE()
	ON_WM_SETFOCUS()
	ON_WM_KILLFOCUS()
END_MESSAGE_MAP()



// CSkinEdit 消息处理程序
void CSkinEdit::OnMouseMove(UINT nFlags, CPoint point)
{
	if (!m_bTracking)
	{
		TRACKMOUSEEVENT tme;
		tme.cbSize = sizeof(tme);
		tme.hwndTrack = m_hWnd;
		tme.dwFlags = TME_LEAVE | TME_HOVER;
		tme.dwHoverTime = 50;
		m_bTracking = (bool)_TrackMouseEvent(&tme);
	}

	CEdit::OnMouseMove(nFlags, point);
}
LRESULT CSkinEdit::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
	m_bTracking = FALSE;
	m_bHover=FALSE;
	DrawBorder();
	return 0;
}

LRESULT CSkinEdit::OnMouseHover(WPARAM wParam, LPARAM lParam)
{
	m_bHover=TRUE;
	DrawBorder();
	return 0;
}
void CSkinEdit::OnSetFocus(CWnd* pOldWnd)
{
	CEdit::OnSetFocus(pOldWnd);
	m_bFocus=TRUE;
	DrawBorder();
}

void CSkinEdit::OnKillFocus(CWnd* pNewWnd)
{
	CEdit::OnKillFocus(pNewWnd);
	m_bFocus=FALSE;
	DrawBorder();
}
void CSkinEdit::OnNcPaint()
{
	CEdit::OnNcPaint();
	DrawBorder();
}
void CSkinEdit::OnPaint()
{
	CEdit::OnPaint();
	DrawBorder();
}

void CSkinEdit::DrawBorder()
{
	HDC hDC=::GetWindowDC(m_hWnd);
	CRect rc;
	::GetWindowRect(m_hWnd,&rc);
	rc=CRect(0,0,rc.right-rc.left,rc.bottom-rc.top);
	if(m_bHover){
		::FrameRect(hDC,&rc,m_HotOrderBrush1);
		rc.InflateRect(-1,-1);
		::FrameRect(hDC,&rc,m_HotOrderBrush2);
	}else if(m_bFocus){
		::FrameRect(hDC,&rc,m_ClientBrush);
		rc.InflateRect(-1,-1);
		::FrameRect(hDC,&rc,m_HotOrderBrush2);
	}else{
		::FrameRect(hDC,&rc,m_ClientBrush);
		rc.InflateRect(-1,-1);
		::FrameRect(hDC,&rc,m_hOrderBrush);
	}
	::ReleaseDC(m_hWnd,hDC);
}


“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:1024 设计师:我叫白小胖 返回首页
评论 12

打赏作者

邓学彬

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值