SkinButton.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #ifndef BUTTON_HEAD_FILE
  2. #define BUTTON_HEAD_FILE
  3. #include "ImageEx.h"
  4. #include "RenderManager.h"
  5. #pragma once
  6. // 当前按钮是图片适应按钮大小;
  7. // 可以设置按钮来适应图片大小;
  8. //按妞类型
  9. enum UI_BUTTON_TYPE
  10. {
  11. en_PushButton,
  12. en_CheckButton,
  13. en_RadioButton,
  14. en_IconButton,
  15. en_MenuButton
  16. };
  17. // CButtonEx
  18. class CSkinButton : public CButton
  19. {
  20. DECLARE_DYNAMIC(CSkinButton)
  21. //资源定义
  22. public:
  23. // 4态背景;
  24. CImageEx* m_pBackImgN;
  25. CImageEx* m_pBackImgH;
  26. CImageEx* m_pBackImgD;
  27. CImageEx* m_pBackImgF;
  28. // 勾选框状态;
  29. CImageEx* m_pCheckImgN;
  30. CImageEx* m_pCheckImgH;
  31. CImageEx* m_pCheckImgTickN;
  32. CImageEx* m_pCheckImgTickH;
  33. // 箭头和图标;
  34. CImageEx * m_pArrowImg, * m_pIconImg;
  35. //变量定义
  36. protected:
  37. BOOL m_bFocus, m_bPress, m_bHover, m_bMouseTracking;
  38. UI_BUTTON_TYPE m_nBtnType;
  39. HMENU m_hMenu;
  40. HDC m_hBackDC;
  41. HFONT m_Font;
  42. DWORD m_dwTextAlign;
  43. //COLORREF m_colDefText; //默认文字
  44. COLORREF m_colNormalText; //正常文字
  45. COLORREF m_colSelectText; //高亮文字
  46. COLORREF m_colDisableText; //失效文字
  47. COLORREF m_colReadOnlyText; //只读文字
  48. BOOL m_bTransparent;
  49. HDC m_hParentDC;
  50. //函数定义
  51. public:
  52. //构造函数
  53. CSkinButton();
  54. //析构函数
  55. virtual ~CSkinButton();
  56. //重载函数
  57. protected:
  58. //消息循环
  59. virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
  60. //设置函数
  61. public:
  62. //设置类型
  63. void SetButtonType(UI_BUTTON_TYPE type);
  64. //调整位置
  65. void SetSize(int nWidth,int nHeight);
  66. //设置菜单
  67. void SetMenu(HMENU hMenu);
  68. //获取字体
  69. HFONT GetCtrlFont(){return m_Font;};
  70. //矩形居中
  71. void CalcCenterRect(RECT& rcDest, int cx, int cy, RECT& rcCenter);
  72. //绘制背景
  73. void DrawParentWndBg(HWND hWnd,HDC hDC);
  74. //设置背景
  75. void SetParentBack(HDC hDC){ m_bTransparent = true; m_hParentDC = hDC;}
  76. //资源加载
  77. public:
  78. //设置资源
  79. BOOL SetBackImage(LPCTSTR lpNormal, LPCTSTR lpHoven, LPCTSTR lpDown, LPCTSTR lpFocus,CONST LPRECT lprcNinePart=NULL);
  80. //设置资源
  81. BOOL SetCheckImage(LPCTSTR lpNormal, LPCTSTR lpHoven, LPCTSTR lpTickNormal, LPCTSTR lpTickHoven);
  82. //设置资源
  83. BOOL SetIconImage(LPCTSTR lpszFileName);
  84. //设置资源
  85. BOOL SetMenuImage(LPCTSTR lpszFileName);
  86. //绘画函数
  87. public:
  88. //PUSH按钮
  89. void DrawPushButton(CDC* pDC,RECT &rcClient);
  90. //Check按钮
  91. void DrawCheckButton(CDC* pDC,RECT &rcClient);
  92. //Check按钮
  93. void DrawIConButton(CDC* pDC,RECT &rcClient);
  94. //Check按钮
  95. void DrawMenuButton(CDC* pDC,RECT &rcClient);
  96. //消息函数
  97. protected:
  98. //鼠标移动
  99. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  100. //鼠标离开
  101. afx_msg LRESULT OnMouseLeave(WPARAM wparam, LPARAM lparam);
  102. //重绘背景
  103. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  104. //销毁消息
  105. afx_msg void OnDestroy();
  106. //左键按下
  107. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  108. //左键抬起
  109. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  110. //设置焦点
  111. afx_msg void OnSetFocus(CWnd* pOldWnd);
  112. //焦点丢失
  113. afx_msg void OnKillFocus(CWnd* pNewWnd);
  114. //绘制消息
  115. afx_msg void OnPaint();
  116. //左键双击
  117. afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
  118. protected:
  119. DECLARE_MESSAGE_MAP()
  120. };
  121. #endif