编辑框等控件边框美化(继承CEdit,然后覆盖OnMouseLeave, OnSetFocus, OnPaint函数即可。原来的CEdit虽然代码不可见,但它也是有句柄的,照样随便画)

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

编辑框等控件边框美化(继承CEdit,然后覆盖OnMouseLeave, OnSetFocus, OnPaint函数即可。原来的CEdit虽然代码不可见,但它也是有句柄的,照样随便画)

编辑框等控件边框美化(继承CEdit,然后覆盖OnMouseLeave, OnSetFocus, OnPaint函数即可。原来的CEdit虽然代码不可见,但它也是有句柄的,照样随便画)

    1. // SkinEdit.cpp : 实现文件
    2. //
    3. #include "stdafx.h"
    4. #include "SkinEdit.h"
    5. // CSkinEdit
    6. IMPLEMENT_DYNAMIC(CSkinEdit, CEdit)
    7. CSkinEdit::CSkinEdit()
    8. {
    9. m_bTracking=m_bHover=m_bFocus=FALSE;
    10. m_ClientBrush=::CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
    11. m_hOrderBrush=::CreateSolidBrush(GetSysColor(COLOR_WINDOWFRAME));
    12. m_HotOrderBrush1=::CreateSolidBrush(0xFDC860);
    13. m_HotOrderBrush2=::CreateSolidBrush(0xE7AC49);
    14. }
    15. CSkinEdit::~CSkinEdit()
    16. {
    17. DeleteObject(m_ClientBrush);
    18. DeleteObject(m_hOrderBrush);
    19. DeleteObject(m_HotOrderBrush1);
    20. DeleteObject(m_HotOrderBrush2);
    21. }
    22. BEGIN_MESSAGE_MAP(CSkinEdit, CEdit)
    23. ON_WM_NCPAINT()
    24. ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
    25. ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)
    26. ON_WM_MOUSEMOVE()
    27. ON_WM_SETFOCUS()
    28. ON_WM_KILLFOCUS()
    29. END_MESSAGE_MAP()
    30. // CSkinEdit 消息处理程序
    31. void CSkinEdit::OnMouseMove(UINT nFlags, CPoint point)
    32. {
    33. if (!m_bTracking)
    34. {
    35. TRACKMOUSEEVENT tme;
    36. tme.cbSize = sizeof(tme);
    37. tme.hwndTrack = m_hWnd;
    38. tme.dwFlags = TME_LEAVE | TME_HOVER;
    39. tme.dwHoverTime = 50;
    40. m_bTracking = (bool)_TrackMouseEvent(&tme);
    41. }
    42. CEdit::OnMouseMove(nFlags, point);
    43. }
    44. LRESULT CSkinEdit::OnMouseLeave(WPARAM wParam, LPARAM lParam)
    45. {
    46. m_bTracking = FALSE;
    47. m_bHover=FALSE;
    48. DrawBorder();
    49. return 0;
    50. }
    51. LRESULT CSkinEdit::OnMouseHover(WPARAM wParam, LPARAM lParam)
    52. {
    53. m_bHover=TRUE;
    54. DrawBorder();
    55. return 0;
    56. }
    57. void CSkinEdit::OnSetFocus(CWnd* pOldWnd)
    58. {
    59. CEdit::OnSetFocus(pOldWnd);
    60. m_bFocus=TRUE;
    61. DrawBorder();
    62. }
    63. void CSkinEdit::OnKillFocus(CWnd* pNewWnd)
    64. {
    65. CEdit::OnKillFocus(pNewWnd);
    66. m_bFocus=FALSE;
    67. DrawBorder();
    68. }
    69. void CSkinEdit::OnNcPaint()
    70. {
    71. CEdit::OnNcPaint();
    72. DrawBorder();
    73. }
    74. void CSkinEdit::OnPaint()
    75. {
    76. CEdit::OnPaint();
    77. DrawBorder();
    78. }
    79. void CSkinEdit::DrawBorder()
    80. {
    81. HDC hDC=::GetWindowDC(m_hWnd);
    82. CRect rc;
    83. ::GetWindowRect(m_hWnd,&rc);
    84. rc=CRect(0,0,rc.right-rc.left,rc.bottom-rc.top);
    85. if(m_bHover){
    86. ::FrameRect(hDC,&rc,m_HotOrderBrush1);
    87. rc.InflateRect(-1,-1);
    88. ::FrameRect(hDC,&rc,m_HotOrderBrush2);
    89. }else if(m_bFocus){
    90. ::FrameRect(hDC,&rc,m_ClientBrush);
    91. rc.InflateRect(-1,-1);
    92. ::FrameRect(hDC,&rc,m_HotOrderBrush2);
    93. }else{
    94. ::FrameRect(hDC,&rc,m_ClientBrush);
    95. rc.InflateRect(-1,-1);
    96. ::FrameRect(hDC,&rc,m_hOrderBrush);
    97. }
    98. ::ReleaseDC(m_hWnd,hDC);
    99. }

http://blog.csdn.net/CometNet/article/details/9194751

上一篇:Android UiAutomator


下一篇:python数据结构与算法第十五天【二叉树】