Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CoolCalendar a perpetual calendar control

0.00/5 (No votes)
14 Feb 2001 1  
An ownderdrawn perpetual calendar control
  • Download Perpetual Calendar Project 44 Kb
  • Background

    During my career I have designed numerous user interfaces and widgets. I have yet to see a calendar that has a perpetual or rolling feature built in. By this I mean to change the month by selecting on the previous or next months days, rather that moving from the calendar interface to the month combobox. Well hopefully this calendar overcomes some of the shortfalls most calendar controls have on the market.

    Features

    • Spinner control (optional) to scroll 7 days at a time.
    • Perpetual or rolling functionality allows user to click on previous and next month.
    • Programmatically attach a note to day
    • Fulfills UI guidelines
    • Date select notification

    Interface

    COleDateTime GetDate() Gets the currently selected date
    void ShowSpinner(BOOL bShow); Shows or hides the month spinner
    BOOL SetDate(COleDateTime tm); Sets the current date
    BOOL AddNote(COleDateTime& date, CString strNote, BOOL bReplace); Attaches a note to a date
    void DeleteNote(COleDateTime& date); Deletes a note from a date
    void ClearAllNotes(); Removes all notes

    Implemention

    Files:

    • CalWnd.h & CalWnd.cpp (Main calendar functionality)
    • CalBtn.h & CalBtn.cpp (Calendar button objects)
    • Popup.h & Popup.cpp (Popup Context menu)
    • NoEdit.h & NoEdit.cpp (Disabled edit box)

    In your windows header file that's going host the control, include "calwnd.h"

    // Include calendar and dependency files
    
    #include "CalWnd.h"
    
    

    Now make a CCalWnd object a member of your hosting window class

    class CMyWnd
    {
    public:
    ... Some other stuff
    protected:
        CCalWnd	m_wndCalendar;  
    
    

    Now create the calendar window, usually done when the hosting window is created.

    int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {	
    	// Call base class implementation of OnCreate first
    
    	if (CWnd ::OnCreate(lpCreateStruct) == -1)
    		return -1;
    	
    
    	// Now create our calendar control
    
    	// This creates the window at the left, top position.
    
    	// The calendar automatically sizes...
    
    	if (m_wndCalendar.Create(NULL,"Calendar",
    	                         WS_VISIBLE|WS_CHILD,
    	                         CRect(20,20,0,0),this,0x0101) == -1)
    		return -1;
    	... Some other code
    

    Now we need to implement a handler for the date change notification. (When the user clicks on a date). This is inserted your hosting windows .cpp file. Put this outside of the AFX_MSG_MAP comments.

    BEGIN_MESSAGE_MAP(CChildView,CWnd )
    	//{{AFX_MSG_MAP(CChildView)
    
    	ON_WM_PAINT()
    	ON_WM_CREATE()
    	ON_WM_LBUTTONDBLCLK()
    	//}}AFX_MSG_MAP
    
    	ON_MESSAGE(WM_DATE_NOTIFY,OnDateNotify) // <--- HERE
    
    END_MESSAGE_MAP()

    This is inserted your hosting windows .h file. Put this outside of the AFX_MSG_MAP comments.

    //{{AFX_MSG(CChildView)
    
    	afx_msg void OnPaint();
    	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
    	//}}AFX_MSG
    
    	afx_msg LRESULT OnDateNotify(WPARAM wParam, LPARAM nId); // <--- HERE
    
    	DECLARE_MESSAGE_MAP()
    

    On finally the handler itself.

    LRESULT CChildView::OnDateNotify(WPARAM wParam, LPARAM nControlId)
    {
    	COleDateTime tm = m_wndCalendar.GetDate();
    
    	TRACE("Date Selected %s for Control ID %d\n",tm.Format("%c"), nControlId);
    	return 0;
    }

    See the example for further use of the calendar. Please contact me if you find bugs, or you would like to see further functionality.

    Happy coding... :)

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here