GdipButton.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // GdipButton.h : Version 1.0 - see article at CodeProject.com
  3. //
  4. // Author: Darren Sessions
  5. //
  6. //
  7. // Description:
  8. // GdipButton is a CButton derived control that uses GDI+
  9. // to support alternate image formats
  10. //
  11. // History
  12. // Version 1.0 - 2008 June 10
  13. // - Initial public release
  14. //
  15. // License:
  16. // This software is released under the Code Project Open License (CPOL),
  17. // which may be found here: http://www.codeproject.com/info/eula.aspx
  18. // You are free to use this software in any way you like, except that you
  19. // may not sell this source code.
  20. //
  21. // This software is provided "as is" with no expressed or implied warranty.
  22. // I accept no liability for any damage or loss of business that this
  23. // software may cause.
  24. //
  25. ///////////////////////////////////////////////////////////////////////////////
  26. #pragma once
  27. // GdipButton.h : header file
  28. //
  29. class CGdiPlusBitmapResource;
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CGdipButton window
  32. class CGdipButton : public CButton
  33. {
  34. public:
  35. CGdipButton();
  36. virtual ~CGdipButton();
  37. // image types
  38. enum {
  39. STD_TYPE = 0,
  40. ALT_TYPE,
  41. DIS_TYPE
  42. };
  43. // sets the image type
  44. void SetImage(int type);
  45. void CGdipButton::Test(CString c);
  46. BOOL LoadAltImage(UINT id, LPCTSTR pType);
  47. BOOL LoadStdImage(UINT id, LPCTSTR pType);
  48. BOOL LoadStdImageDPI(int dpi, UINT id96, UINT id120, UINT id144, UINT id168, UINT id192, LPCTSTR pType, UINT id225 = 0, UINT id250 = 0, UINT id275 = 0, UINT id300 = 0, UINT id325 = 0, UINT id350 = 0);
  49. // if false, disables the press state and uses grayscale image if it exists
  50. void EnableButton(BOOL bEnable = TRUE) { m_bIsDisabled = !bEnable; }
  51. // in toggle mode each press toggles between std and alt images
  52. void EnableToggle(BOOL bEnable = TRUE);
  53. // return the enable/disable state
  54. BOOL IsDisabled(void) {return (m_bIsDisabled == TRUE); }
  55. void SetBkGnd(CDC* pDC);
  56. void SetToolTipText(CString spText, BOOL bActivate = TRUE);
  57. void SetToolTipText(UINT nId, BOOL bActivate = TRUE);
  58. void SetHorizontal(bool ImagesAreLaidOutHorizontally = FALSE);
  59. void DeleteToolTip();
  60. void Reset();
  61. protected:
  62. void PaintBk(CDC* pDC);
  63. void PaintBtn(CDC* pDC);
  64. BOOL m_bHaveAltImage;
  65. BOOL m_bHaveBitmaps;
  66. BOOL m_bIsDisabled;
  67. BOOL m_bIsToggle;
  68. BOOL m_bIsHovering;
  69. BOOL m_bIsTracking;
  70. int m_nCurType;
  71. CGdiPlusBitmapResource* m_pAltImage;
  72. CGdiPlusBitmapResource* m_pStdImage;
  73. CString m_tooltext;
  74. CToolTipCtrl* m_pToolTip;
  75. void InitToolTip();
  76. virtual void PreSubclassWindow();
  77. virtual void DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/);
  78. virtual BOOL PreTranslateMessage(MSG* pMsg);
  79. //{{AFX_MSG(CGdipButton)
  80. afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
  81. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  82. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  83. afx_msg LRESULT OnMouseLeave(WPARAM wparam, LPARAM lparam);
  84. afx_msg LRESULT OnMouseHover(WPARAM wparam, LPARAM lparam) ;
  85. //}}AFX_MSG
  86. DECLARE_MESSAGE_MAP()
  87. private:
  88. CDC m_dcBk; // button background
  89. CDC m_dcStd; // standard button
  90. CDC m_dcStdP; // standard button pressed
  91. CDC m_dcStdH; // standard button hot
  92. CDC m_dcAlt; // alternate button
  93. CDC m_dcAltP; // alternate button pressed
  94. CDC m_dcAltH; // alternate button hot
  95. CDC m_dcGS; // grayscale button (does not have a hot or pressed state)
  96. CDC* m_pCurBtn; // current pointer to one of the above
  97. };