源码说明:美化能获取焦点控件的边框颜色,获取焦点后颜色不同(类似彗星小助手、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);
- }
http://blog.csdn.net/CometNet/article/details/9194751