SkinButton.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /************************************************************************
  2. * 程序名: 精仿QQ主界面
  3. * 制作人: 李克平, 2011年04月11日
  4. * 版本号: 1.0
  5. ************************************************************************/
  6. #pragma once
  7. #include <atlimage.h>
  8. #include "EnBitmap.h"
  9. // CSkinButton
  10. class CSkinButton : public CButton
  11. {
  12. DECLARE_DYNAMIC(CSkinButton)
  13. public:
  14. CSkinButton();
  15. virtual ~CSkinButton();
  16. typedef enum state
  17. {
  18. NORMAL,
  19. HOVER,
  20. DOWN,
  21. DISABLE
  22. }state;
  23. protected:
  24. DECLARE_MESSAGE_MAP()
  25. //CImage m_imgNormal;
  26. //CImage m_imgHover;
  27. //CImage m_imgDown;
  28. //CImage m_imgDisable;
  29. CEnBitmap m_bmpButton;
  30. CEnBitmap m_bmpNormal;
  31. CEnBitmap m_bmpHover;
  32. CEnBitmap m_bmpDown;
  33. CEnBitmap m_bmpDisable;
  34. CEnBitmap m_bmpIconButton;
  35. private:
  36. state m_state;
  37. COLORREF m_fg, m_bg;
  38. COLORREF m_crBack;
  39. bool m_bMouseOver;
  40. BOOL m_bDown;
  41. bool m_bEnabled;
  42. CFont *m_pFont;
  43. bool m_bDCStored;//是否已经保存背景图
  44. CImage m_hMouseInIcon;
  45. CImage m_hMouseOutIcon;
  46. CPoint m_textPos;
  47. CRect m_iconRect;
  48. CDC m_memDC;
  49. public:
  50. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  51. afx_msg void OnTimer(UINT_PTR nIDEvent);
  52. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  53. afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  54. protected:
  55. virtual void PreSubclassWindow();
  56. virtual void DrawItem(LPDRAWITEMSTRUCT lpDIS);
  57. protected:
  58. //在按钮中填充颜色
  59. void DrawFilledRect(CDC *DC, CRect R, COLORREF color);
  60. //设置按钮上的字体颜色
  61. void DrawButtonText(CDC *DC, CRect R, CString str, COLORREF TextColor);
  62. void DrawButton();
  63. public:
  64. void SetOwnerDraw(bool IsDraw);
  65. void SetImage(UINT nNormalID, UINT nHoverID, UINT nDownID, UINT nDisableID);
  66. void SetImage(CString strNormal, CString strHover, CString strDown, CString strDisable);
  67. void loadHoverBGBmp(LPCTSTR szImagePath);
  68. void LoadImage(LPCTSTR szImagePath,COLORREF crBack = RGB(255,0,255),BOOL bResetSize =TRUE);
  69. BOOL LoadBitmap(UINT uIDRes,COLORREF crBack,BOOL bResetSize = TRUE);
  70. void SetIcon(CString strMouseOut,CString strMouseIn);
  71. void SetColor(COLORREF fgcolor,COLORREF bgcolor);
  72. void SetTextPos(CPoint point);
  73. CEnBitmap* GetPaintBmp(){return &m_bmpNormal;}
  74. CImage* GetPaintIcon(){return &m_hMouseOutIcon;}
  75. CPoint GetTextPos(){return m_textPos;}
  76. COLORREF GetFGColor() { return m_fg; }
  77. COLORREF GetBGColor() { return m_bg; }
  78. CRect GetRectInParent();
  79. void SetStatusBmp();
  80. CRect GetIconRect(){return m_iconRect;}
  81. int Width(){return m_bmpNormal.Width();}
  82. int Heighth(){return m_bmpNormal.Height();}
  83. void ResetButtonSize(BOOL bResetSize);
  84. public:
  85. afx_msg void OnEnable(BOOL bEnable);
  86. };