YMSelector.h
上传用户:baiduw
上传日期:2007-01-01
资源大小:23k
文件大小:6k
源码类别:

界面编程

开发平台:

Visual C++

  1. // YMSelector.h
  2. // Control to select year and month
  3. // Designed and developed by Shekar Narayanan
  4. // ShekarNarayanan@Hotmail.com
  5. // 
  6. #if !defined(AFX_YMSELECTOR_H__12C342F1_008C_11D2_AECD_0004AC31E75C__INCLUDED_)
  7. #define AFX_YMSELECTOR_H__12C342F1_008C_11D2_AECD_0004AC31E75C__INCLUDED_
  8. #if _MSC_VER >= 1000
  9. #pragma once
  10. #endif // _MSC_VER >= 1000
  11. // YMSelector.h : header file
  12. //
  13. #define     START_YEAR      1900
  14. #define     END_YEAR        2050    
  15. #define     YM_SELECTED     WM_USER + 50
  16. #define     YM_ABORTED      WM_USER + 51
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CYMPopUp window
  19. // Used by the YMSelector control
  20. class CYMPopUp : public CWnd
  21. {
  22. // Construction
  23. public:
  24. CYMPopUp(CPoint p, CWnd* pParent, int nYear = -1, int nMonth = -1);
  25. // Attributes
  26. public:
  27. // Operations
  28. public:
  29.     BOOL Create(CPoint p, CWnd* pParent);
  30. // Overrides
  31. // ClassWizard generated virtual function overrides
  32. //{{AFX_VIRTUAL(CYMPopUp)
  33. //}}AFX_VIRTUAL
  34. // Implementation
  35. public:
  36. virtual ~CYMPopUp();
  37. // Generated message map functions
  38. protected:
  39. BOOL m_inPlus;
  40. BOOL m_inMinus;
  41.     int     m_nYear;
  42.     int     m_nMonth;
  43.     CBrush  m_bkBrush;
  44.     CWnd*   m_pParent;
  45.     CRect   m_rCells[12];
  46.     CRect   m_rMinus;
  47.     CRect   m_rPlus;
  48.     CRect   m_rYear;
  49. //{{AFX_MSG(CYMPopUp)
  50. afx_msg void OnNcDestroy();
  51. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  52. afx_msg void OnPaint();
  53. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  54. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  55. afx_msg BOOL OnEraseBkgnd(CDC* pDC) ;
  56. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  57. //}}AFX_MSG
  58. DECLARE_MESSAGE_MAP()
  59. };
  60. /////////////////////////////////////////////////////////////////////////////
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CYMSelector window
  63. class CYMSelector : public CButton
  64. {
  65. // Construction
  66. public:
  67. CYMSelector();
  68. // Attributes
  69. public:
  70.     void    SetYear(int y);
  71.     void    SetMonth(int m);
  72.     int     GetYear();
  73.     int     GetMonth();
  74.     LPCTSTR GetMonthString();
  75. // Operations
  76. public:
  77. // Overrides
  78. // ClassWizard generated virtual function overrides
  79. //{{AFX_VIRTUAL(CYMSelector)
  80. public:
  81. virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  82. protected:
  83. virtual void PreSubclassWindow();
  84. //}}AFX_VIRTUAL
  85. // Implementation
  86. public:
  87. virtual ~CYMSelector();
  88. // Generated message map functions
  89. protected:
  90.     int m_nMonth;
  91.     int m_nYear;
  92. //{{AFX_MSG(CYMSelector)
  93. afx_msg void OnClicked();
  94. //}}AFX_MSG
  95.     afx_msg LONG YMSelected(WPARAM wParam = 0, LPARAM lParam = 0);
  96.     afx_msg LONG YMAborted (WPARAM wParam = 0, LPARAM lParam = 0);
  97. DECLARE_MESSAGE_MAP()
  98. };
  99. // MemDC.h : header file
  100. //
  101. //////////////////////////////////////////////////
  102. // CMemDC - memory DC
  103. //
  104. // Author: Keith Rule
  105. // Email:  keithr@europa.com
  106. // Copyright 1996-1997, Keith Rule
  107. //
  108. // You may freely use or modify this code provided this
  109. // Copyright is included in all derived versions.
  110. //
  111. // History - 10/3/97 Fixed scrolling bug.
  112. //                   Added print support.
  113. //           25 feb 98 - fixed minor assertion bug
  114. //
  115. // This class implements a memory Device Context
  116. class CMemDC : public CDC
  117. {
  118. public:
  119.     // constructor sets up the memory DC
  120.     CMemDC(CDC* pDC) : CDC()
  121.     {
  122.         ASSERT(pDC != NULL);
  123.         m_pDC = pDC;
  124.         m_pOldBitmap = NULL;
  125.         m_bMemDC = !pDC->IsPrinting();
  126.               
  127.         if (m_bMemDC)    // Create a Memory DC
  128.         {
  129.             pDC->GetClipBox(&m_rect);
  130.             CreateCompatibleDC(pDC);
  131.             m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
  132.             m_pOldBitmap = SelectObject(&m_bitmap);
  133.             SetWindowOrg(m_rect.left, m_rect.top);
  134.         }
  135.         else        // Make a copy of the relevent parts of the current DC for printing
  136.         {
  137.             m_bPrinting = pDC->m_bPrinting;
  138.             m_hDC       = pDC->m_hDC;
  139.             m_hAttribDC = pDC->m_hAttribDC;
  140.         }
  141.     }
  142.     
  143.     // Destructor copies the contents of the mem DC to the original DC
  144.     ~CMemDC()
  145.     {
  146.         if (m_bMemDC) 
  147.         {    
  148.             // Copy the offscreen bitmap onto the screen.
  149.             m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
  150.                           this, m_rect.left, m_rect.top, SRCCOPY);
  151.             //Swap back the original bitmap.
  152.             SelectObject(m_pOldBitmap);
  153.         } else {
  154.             // All we need to do is replace the DC with an illegal value,
  155.             // this keeps us from accidently deleting the handles associated with
  156.             // the CDC that was passed to the constructor.
  157.             m_hDC = m_hAttribDC = NULL;
  158.         }
  159.     }
  160.     // Allow usage as a pointer
  161.     CMemDC* operator->() {return this;}
  162.         
  163.     // Allow usage as a pointer
  164.     operator CMemDC*() {return this;}
  165. private:
  166.     CBitmap  m_bitmap;      // Offscreen bitmap
  167.     CBitmap* m_pOldBitmap;  // bitmap originally found in CMemDC
  168.     CDC*     m_pDC;         // Saves CDC passed in constructor
  169.     CRect    m_rect;        // Rectangle of drawing area.
  170.     BOOL     m_bMemDC;      // TRUE if CDC really is a Memory DC.
  171. };
  172. /////////////////////////////////////////////////////////////////////////////
  173. //{{AFX_INSERT_LOCATION}}
  174. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  175. #endif // !defined(AFX_YMSELECTOR_H__12C342F1_008C_11D2_AECD_0004AC31E75C__INCLUDED_)