BtnST.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // Class: CButtonST
  3. //
  4. // Compiler: Visual C++
  5. // Tested on: Visual C++ 5.0
  6. // Visual C++ 6.0
  7. //
  8. // Version: See GetVersionC() or GetVersionI()
  9. //
  10. // Created: xx/xxxx/1998
  11. // Updated: 14/June/2001
  12. //
  13. // Author: Davide Calabro' davide_calabro@yahoo.com
  14. //
  15. #ifndef _BTNST_H
  16. #define _BTNST_H
  17. #if _MSC_VER >= 1000
  18. #pragma once
  19. #endif // _MSC_VER >= 1000
  20. // CBtnST.h : header file
  21. //
  22. // Comment this if you don't want that CButtonST hilights itself
  23. // also when the window is inactive (like happens in Internet Explorer)
  24. //#define ST_LIKEIE
  25. // Return values
  26. #ifndef BTNST_OK
  27. #define BTNST_OK 0
  28. #endif
  29. #ifndef BTNST_INVALIDRESOURCE
  30. #define BTNST_INVALIDRESOURCE 1
  31. #endif
  32. #ifndef BTNST_FAILEDMASK
  33. #define BTNST_FAILEDMASK 2
  34. #endif
  35. #ifndef BTNST_INVALIDINDEX
  36. #define BTNST_INVALIDINDEX 3
  37. #endif
  38. class CButtonST : public CButton
  39. {
  40. public:
  41. CButtonST();
  42. ~CButtonST();
  43. enum {ST_ALIGN_HORIZ, ST_ALIGN_VERT, ST_ALIGN_HORIZ_RIGHT};
  44. enum { BTNST_COLOR_BK_IN = 0, // Background color when mouse is INside
  45. BTNST_COLOR_FG_IN, // Text color when mouse is INside
  46. BTNST_COLOR_BK_OUT, // Background color when mouse is OUTside
  47. BTNST_COLOR_FG_OUT, // Text color when mouse is OUTside
  48. BTNST_MAX_COLORS
  49. };
  50. // ClassWizard generated virtual function overrides
  51. //{{AFX_VIRTUAL(CButtonST)
  52. public:
  53. virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  54. virtual BOOL PreTranslateMessage(MSG* pMsg);
  55. protected:
  56. virtual void PreSubclassWindow();
  57. virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
  58. //}}AFX_VIRTUAL
  59. public:
  60. DWORD SetAutoRepeat(BOOL bSet, DWORD dwMilliseconds = 100);
  61. DWORD SetURL(LPCTSTR lpszURL);
  62. DWORD GetColor(BYTE byColorIndex, COLORREF* crpColor);
  63. DWORD SetColor(BYTE byColorIndex, COLORREF crColor, BOOL bRepaint = TRUE);
  64. DWORD SetDefaultColors(BOOL bRepaint = TRUE);
  65. int GetCheck();
  66. void SetCheck(int nCheck, BOOL bRepaint = TRUE);
  67. void DrawTransparent(BOOL bRepaint = FALSE);
  68. BOOL GetDefault();
  69. void SetTooltipText(int nId, BOOL bActivate = TRUE);
  70. void SetTooltipText(LPCTSTR lpszText, BOOL bActivate = TRUE);
  71. void ActivateTooltip(BOOL bEnable = TRUE);
  72. BOOL SetBtnCursor(int nCursorId = NULL);
  73. void SetFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint = FALSE);
  74. void SetAlign(int nAlign);
  75. int GetAlign();
  76. void SetFlat(BOOL bState = TRUE);
  77. BOOL GetFlat();
  78. void DrawBorder(BOOL bEnable = TRUE);
  79. DWORD SetIcon(int nIconInId, int nIconOutId = NULL);
  80. DWORD SetIcon(HICON hIconIn, HICON hIconOut = NULL);
  81. DWORD SetBitmaps(int nBitmapIn, COLORREF crTransColorIn, int nBitmapOut = NULL, COLORREF crTransColorOut = 0);
  82. DWORD SetBitmaps(HBITMAP hBitmapIn, COLORREF crTransColorIn, HBITMAP hBitmapOut = NULL, COLORREF crTransColorOut = 0);
  83. static short GetVersionI() {return 32;}
  84. static LPCTSTR GetVersionC() {return (LPCTSTR)_T("3.2");}
  85. protected:
  86. //{{AFX_MSG(CButtonST)
  87. afx_msg void OnCaptureChanged(CWnd *pWnd);
  88. afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  89. afx_msg void OnKillFocus(CWnd* pNewWnd);
  90. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  91. afx_msg void OnSysColorChange();
  92. afx_msg BOOL OnClicked();
  93. afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
  94. afx_msg void OnEnable(BOOL bEnable);
  95. afx_msg void OnCancelMode();
  96. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  97. //}}AFX_MSG
  98. afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
  99. virtual DWORD OnDrawBackground(CDC* pDC, LPCRECT pRect);
  100. virtual DWORD OnDrawBorder(CDC* pDC, LPCRECT pRect);
  101. BOOL m_bDrawTransparent;
  102. BOOL m_bMouseOnButton;
  103. BOOL m_bIsPressed;
  104. BOOL m_bIsFocused;
  105. BOOL m_bIsDisabled;
  106. COLORREF m_crColors[BTNST_MAX_COLORS];
  107. private:
  108. void CancelHover();
  109. void PrepareImageRect(BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, DWORD dwWidth, DWORD dwHeight, CRect* rpImage);
  110. HBITMAP CreateBitmapMask(HBITMAP hSourceBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTransColor);
  111. void DrawTheBitmap(CDC* pDC, BOOL bHasTitle, RECT *rItem, CRect *rCaption, BOOL bIsPressed, BOOL bIsDisabled);
  112. void FreeResources(BOOL bCheckForNULL = TRUE);
  113. void DrawTheIcon(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, BOOL bIsDisabled);
  114. void InitToolTip();
  115. void PaintBk(CDC* pDC);
  116. int m_nAlign;
  117. BOOL m_bDrawBorder;
  118. BOOL m_bIsFlat;
  119. BOOL m_bDrawFlatFocus;
  120. BOOL m_bAutoRepeat;
  121. HWND m_hWndAutoRepeat;
  122. UINT m_nMsgAutoRepeat;
  123. DWORD m_dwPeriodAutoRepeat;
  124. HCURSOR m_hCursor;
  125. CToolTipCtrl m_ToolTip;
  126. #pragma pack(1)
  127. typedef struct _STRUCT_ICONS
  128. {
  129. HICON hIcon; // Handle to icon
  130. DWORD dwWidth; // Width of icon
  131. DWORD dwHeight; // Height of icon
  132. } STRUCT_ICONS;
  133. #pragma pack()
  134. #pragma pack(1)
  135. typedef struct _STRUCT_BITMAPS
  136. {
  137. HBITMAP hBitmap; // Handle to bitmap
  138. DWORD dwWidth; // Width of bitmap
  139. DWORD dwHeight; // Height of bitmap
  140. HBITMAP hMask; // Handle to mask bitmap
  141. COLORREF crTransparent; // Transparent color
  142. } STRUCT_BITMAPS;
  143. #pragma pack()
  144. STRUCT_ICONS m_csIcons[2];
  145. STRUCT_BITMAPS m_csBitmaps[2];
  146. CDC m_dcBk;
  147. CBitmap m_bmpBk;
  148. CBitmap* m_pbmpOldBk;
  149. BOOL m_bIsDefault;
  150. BOOL m_bIsCheckBox;
  151. int m_nCheck;
  152. TCHAR m_szURL[_MAX_PATH];
  153. DECLARE_MESSAGE_MAP()
  154. };
  155. /////////////////////////////////////////////////////////////////////////////
  156. //{{AFX_INSERT_LOCATION}}
  157. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  158. #endif