Click here to Skip to main content
15,868,016 members
Articles / Desktop Programming / MFC
Article

CoolCalendar a perpetual calendar control

Rate me:
Please Sign up or sign in to vote.
2.80/5 (6 votes)
14 Feb 2001 134.2K   1.8K   24   17
An ownderdrawn perpetual calendar control
  • Download Perpetual Calendar Project 44 Kb
  • Image 1

    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


    Written By
    Software Developer (Senior) Software Kinetics
    United Kingdom United Kingdom




    Software Kinetics
    are experts in developing customised and bespoke applications and have expertise in the development of desktop, mobile and internet applications on Windows.


    We specialise in:

    • User Interface Design
    • Desktop Development
    • Windows Phone Development
    • Windows Presentation Framework
    • Windows Forms
    • Windows Communication Framework
    • Windows Services
    • Network Applications
    • Database Applications
    • Web Development
    • Web Services
    • Silverlight
    • ASP.net


    Visit Software Kinetics

    Comments and Discussions

     
    GeneralMy vote of 1 Pin
    Sheetal_Joshi8-Dec-09 6:08
    Sheetal_Joshi8-Dec-09 6:08 
    QuestionHow Can I do Pin
    Anonymous12-May-03 23:20
    Anonymous12-May-03 23:20 
    GeneralAnother Problem with TTS_BALLOON Pin
    Joseph Dempsey15-Feb-01 12:02
    Joseph Dempsey15-Feb-01 12:02 
    GeneralRe: Another Problem with TTS_BALLOON Pin
    Uwe Keim15-Feb-01 20:48
    sitebuilderUwe Keim15-Feb-01 20:48 
    GeneralRe: Another Problem with TTS_BALLOON Pin
    Joseph Dempsey16-Feb-01 6:38
    Joseph Dempsey16-Feb-01 6:38 
    GeneralRe: Another Problem with TTS_BALLOON Pin
    NormDroid16-Feb-01 8:13
    professionalNormDroid16-Feb-01 8:13 
    GeneralRe: Another Problem with TTS_BALLOON Pin
    14-Oct-01 19:42
    suss14-Oct-01 19:42 
    GeneralRe: Another Problem with TTS_BALLOON Pin
    pa19685-Jun-06 23:59
    pa19685-Jun-06 23:59 
    GeneralFix the author's homepage URL Pin
    Ammar10-Dec-00 20:52
    Ammar10-Dec-00 20:52 
    GeneralRe: Fix the author's homepage URL Pin
    Erik Thompson11-Dec-00 4:46
    sitebuilderErik Thompson11-Dec-00 4:46 
    GeneralProblems Pin
    Matt Philmon10-Dec-00 13:44
    Matt Philmon10-Dec-00 13:44 
    GeneralRe: Problems Pin
    NormDroid10-Dec-00 22:17
    professionalNormDroid10-Dec-00 22:17 
    GeneralRe: Problems fix? Pin
    11-Dec-00 12:26
    suss11-Dec-00 12:26 
    GeneralRe: Problems fix? Pin
    NormDroid11-Dec-00 21:44
    professionalNormDroid11-Dec-00 21:44 
    GeneralRe: Problems fix? Pin
    12-Dec-00 11:25
    suss12-Dec-00 11:25 
    GeneralRe: Problems fix? Pin
    NormDroid12-Dec-00 23:33
    professionalNormDroid12-Dec-00 23:33 
    GeneralRe: Problems fix? Pin
    arbrsoft22-Dec-03 5:22
    arbrsoft22-Dec-03 5:22 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.