SkinButton.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /************************************************************************/
  2. /* Copyright (C), 2016-2020, [IT], 保留所有权利;
  3. /* 模 块 名:;
  4. /* 描 述:;
  5. /*
  6. /* 版 本:[V];
  7. /* 作 者:[IT];
  8. /* 日 期:[8/19/2016];
  9. /*
  10. /*
  11. /* 注 意:;
  12. /*
  13. /* 修改记录:[IT];
  14. /* 修改日期:;
  15. /* 修改版本:;
  16. /* 修改内容:;
  17. /************************************************************************/
  18. #pragma once
  19. #include <atlimage.h>
  20. #include "EnBitmap.h"
  21. // CSkinButton
  22. class CSkinButton : public CButton
  23. {
  24. DECLARE_DYNAMIC(CSkinButton)
  25. public:
  26. CSkinButton();
  27. virtual ~CSkinButton();
  28. typedef enum state
  29. {
  30. NORMAL,
  31. HOVER,
  32. DOWN,
  33. DISABLE
  34. }state;
  35. protected:
  36. DECLARE_MESSAGE_MAP()
  37. CEnBitmap m_bmpButton;
  38. CEnBitmap m_bmpNormal;
  39. CEnBitmap m_bmpHover;
  40. CEnBitmap m_bmpDown;
  41. CEnBitmap m_bmpDisable;
  42. CEnBitmap m_bmpIconButton;
  43. private:
  44. // 是否显示按钮本身文本;
  45. BOOL m_bShowOwnerText;
  46. state m_state;
  47. COLORREF m_fg, m_bg;
  48. COLORREF m_crBack;
  49. bool m_bMouseOver;
  50. BOOL m_bDown;
  51. bool m_bEnabled;
  52. CFont *m_pFont;
  53. bool m_bDCStored;//是否已经保存背景图
  54. CImage m_hMouseInIcon;
  55. CImage m_hMouseOutIcon;
  56. CPoint m_textPos;
  57. CRect m_iconRect;
  58. CDC m_memDC;
  59. public:
  60. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  61. afx_msg void OnTimer(UINT_PTR nIDEvent);
  62. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  63. afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  64. protected:
  65. virtual void PreSubclassWindow();
  66. virtual void DrawItem(LPDRAWITEMSTRUCT lpDIS);
  67. protected:
  68. //在按钮中填充颜色
  69. void DrawFilledRect(CDC *DC, CRect R, COLORREF color);
  70. //设置按钮上的字体颜色
  71. void DrawButtonText(CDC *DC, CRect R, CString str, COLORREF TextColor);
  72. void DrawButton();
  73. public:
  74. void ShowOwnerText(IN BOOL bShowOwnerText = TRUE) { m_bShowOwnerText = bShowOwnerText; };
  75. void SetOwnerDraw(bool IsDraw);
  76. void SetImage(UINT nNormalID, UINT nHoverID, UINT nDownID, UINT nDisableID);
  77. void SetImage(CString strNormal, CString strHover, CString strDown, CString strDisable);
  78. void loadHoverBGBmp(LPCTSTR szImagePath);
  79. void LoadImage(LPCTSTR szImagePath,COLORREF crBack = RGB(255,0,255),BOOL bResetSize =TRUE);
  80. BOOL LoadBitmap(UINT uIDRes,COLORREF crBack,BOOL bResetSize = TRUE);
  81. void SetIcon(CString strMouseOut,CString strMouseIn);
  82. void SetColor(COLORREF fgcolor,COLORREF bgcolor);
  83. void SetTextPos(CPoint point);
  84. CEnBitmap* GetPaintBmp(){return &m_bmpNormal;}
  85. CImage* GetPaintIcon(){return &m_hMouseOutIcon;}
  86. CPoint GetTextPos(){return m_textPos;}
  87. COLORREF GetFGColor() { return m_fg; }
  88. COLORREF GetBGColor() { return m_bg; }
  89. CRect GetRectInParent();
  90. void SetStatusBmp();
  91. CRect GetIconRect(){return m_iconRect;}
  92. int Width(){return m_bmpNormal.Width();}
  93. int Heighth(){return m_bmpNormal.Height();}
  94. void ResetButtonSize(BOOL bResetSize);
  95. public:
  96. afx_msg void OnEnable(BOOL bEnable);
  97. };