BtnST.h
上传用户:wangfu1106
上传日期:2014-08-20
资源大小:193k
文件大小:6k
源码类别:

数据库编程

开发平台:

Visual C++

  1. #ifndef _BTNST_H
  2. #define _BTNST_H
  3. #if _MSC_VER >= 1000
  4. #pragma once
  5. #endif // _MSC_VER >= 1000
  6. // CBtnST.h : header file
  7. //
  8. // Comment this if you don't want that CButtonST hilights itself
  9. // also when the window is inactive (like happens in Internet Explorer)
  10. #define ST_LIKEIE
  11. // Comment this if you don't want to use CMemDC class
  12. #define ST_USE_MEMDC
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CButtonST window
  15. class CButtonST : public CButton
  16. {
  17. // Construction
  18. public:
  19.     CButtonST();
  20. ~CButtonST();
  21.     enum {ST_ALIGN_HORIZ, ST_ALIGN_VERT};
  22. // Attributes
  23. public:
  24. // Operations
  25. public:
  26. // Overrides
  27. // ClassWizard generated virtual function overrides
  28.     //{{AFX_VIRTUAL(CButtonST)
  29. public:
  30. virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  31. protected:
  32. virtual void PreSubclassWindow();
  33. //}}AFX_VIRTUAL
  34. // Implementation
  35. public:
  36. BOOL SetBtnCursor(int nCursorId = -1);
  37. void SetFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint = FALSE);
  38. BOOL GetFlatFocus();
  39. void SetDefaultActiveFgColor(BOOL bRepaint = FALSE);
  40. void SetActiveFgColor(COLORREF crNew, BOOL bRepaint = FALSE);
  41. const COLORREF GetActiveFgColor();
  42. void SetDefaultActiveBgColor(BOOL bRepaint = FALSE);
  43. void SetActiveBgColor(COLORREF crNew, BOOL bRepaint = FALSE);
  44. const COLORREF GetActiveBgColor();
  45. void SetDefaultInactiveFgColor(BOOL bRepaint = FALSE);
  46. void SetInactiveFgColor(COLORREF crNew, BOOL bRepaint = FALSE);
  47. const COLORREF GetInactiveFgColor();
  48. void SetDefaultInactiveBgColor(BOOL bRepaint = FALSE);
  49. void SetInactiveBgColor(COLORREF crNew, BOOL bRepaint = FALSE);
  50. const COLORREF GetInactiveBgColor();
  51. void SetShowText(BOOL bShow = TRUE);
  52. BOOL GetShowText();
  53. void SetAlign(int nAlign);
  54. int GetAlign();
  55. void SetFlat(BOOL bState = TRUE);
  56. BOOL GetFlat();
  57. void DrawBorder(BOOL bEnable = TRUE);
  58. void SetIcon(int nIconInId, int nIconOutId = NULL, BYTE cx = 32, BYTE cy = 32);
  59. static const short GetVersionI();
  60. static const char* GetVersionC();
  61. protected:
  62.     //{{AFX_MSG(CButtonST)
  63. afx_msg void OnCaptureChanged(CWnd *pWnd);
  64. afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  65. afx_msg void OnKillFocus(CWnd* pNewWnd);
  66. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  67. //}}AFX_MSG
  68. DECLARE_MESSAGE_MAP()
  69. private:
  70. void DrawTheIcon(CDC* pDC, CString* title, RECT* rcItem, CRect* captionRect, BOOL IsPressed, BOOL IsDisabled);
  71. int m_nAlign;
  72. BOOL m_bShowText;
  73. BOOL m_bDrawBorder;
  74. BOOL m_bIsFlat;
  75. BOOL m_MouseOnButton;
  76. BOOL m_bDrawFlatFocus;
  77. HCURSOR m_hCursor;
  78. HICON m_hIconIn;
  79. HICON m_hIconOut;
  80. BYTE m_cyIcon;
  81. BYTE m_cxIcon;
  82. COLORREF  m_crInactiveBg;
  83.     COLORREF  m_crInactiveFg;
  84.     COLORREF  m_crActiveBg;
  85.     COLORREF  m_crActiveFg;
  86. };
  87. #ifdef ST_USE_MEMDC
  88. //////////////////////////////////////////////////
  89. // CMemDC - memory DC
  90. //
  91. // Author: Keith Rule
  92. // Email:  keithr@europa.com
  93. // Copyright 1996-1997, Keith Rule
  94. //
  95. // You may freely use or modify this code provided this
  96. // Copyright is included in all derived versions.
  97. //
  98. // History - 10/3/97 Fixed scrolling bug.
  99. //                   Added print support.
  100. //           25 feb 98 - fixed minor assertion bug
  101. //
  102. // This class implements a memory Device Context
  103. class CMemDC : public CDC
  104. {
  105. public:
  106.     // constructor sets up the memory DC
  107.     CMemDC(CDC* pDC) : CDC()
  108.     {
  109.         ASSERT(pDC != NULL);
  110.         m_pDC = pDC;
  111.         m_pOldBitmap = NULL;
  112.         m_bMemDC = !pDC->IsPrinting();
  113.               
  114.         if (m_bMemDC)    // Create a Memory DC
  115.         {
  116.             pDC->GetClipBox(&m_rect);
  117.             CreateCompatibleDC(pDC);
  118.             m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
  119.             m_pOldBitmap = SelectObject(&m_bitmap);
  120.             SetWindowOrg(m_rect.left, m_rect.top);
  121.         }
  122.         else        // Make a copy of the relevent parts of the current DC for printing
  123.         {
  124.             m_bPrinting = pDC->m_bPrinting;
  125.             m_hDC       = pDC->m_hDC;
  126.             m_hAttribDC = pDC->m_hAttribDC;
  127.         }
  128.     }
  129.     
  130.     // Destructor copies the contents of the mem DC to the original DC
  131.     ~CMemDC()
  132.     {
  133.         if (m_bMemDC) 
  134.         {    
  135.             // Copy the offscreen bitmap onto the screen.
  136.             m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
  137.                           this, m_rect.left, m_rect.top, SRCCOPY);
  138.             //Swap back the original bitmap.
  139.             SelectObject(m_pOldBitmap);
  140.         } else {
  141.             // All we need to do is replace the DC with an illegal value,
  142.             // this keeps us from accidently deleting the handles associated with
  143.             // the CDC that was passed to the constructor.
  144.             m_hDC = m_hAttribDC = NULL;
  145.         }
  146.     }
  147.     // Allow usage as a pointer
  148.     CMemDC* operator->() {return this;}
  149.         
  150.     // Allow usage as a pointer
  151.     operator CMemDC*() {return this;}
  152. private:
  153.     CBitmap  m_bitmap;      // Offscreen bitmap
  154.     CBitmap* m_pOldBitmap;  // bitmap originally found in CMemDC
  155.     CDC*     m_pDC;         // Saves CDC passed in constructor
  156.     CRect    m_rect;        // Rectangle of drawing area.
  157.     BOOL     m_bMemDC;      // TRUE if CDC really is a Memory DC.
  158. };
  159. #endif
  160. /////////////////////////////////////////////////////////////////////////////
  161. //{{AFX_INSERT_LOCATION}}
  162. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  163. #endif