Use the Calendar Control 8.0 as a Date Picker Control


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

Download demo project.

The Calendar Control 8.0 (mscal.ocx) shipping with Visual Studio 5.0 looks very nice. It can be very simple incorporate in your application as a date picker control.

It has two combo box to quickly change a month and a year. Unfortunetly, when you try to change the month or the year the date sets on NULL value and doesn't highlighted.

In my example I implement a full date picker control using Calendar Control 8.0. I spend some time to find solution how to work with year's and month's comboboxes and I think it will be usefull to share my experience.

I found that IDs of the Month and the Year comboboxes have the respective values 1 and 2. Then, I trap the message event "NewYear"( "NewYear") and when the combobox obtains focus change the year(month) using NextYear()(NextMonth()) and PreviousYear()(PreviousMonth()) methods.

This is a code for NewYear event:

void CDateCal::OnNewYearDateCalendar() 
	// TODO: Add your control notification handler code here
	int nID;

	CWnd* pWnd = GetFocus();
	nID = pWnd->GetDlgCtrlID();	
	CString string;
	pWnd->GetWindowText( string );
	if(2==nID) {//nID =2 - ID combobox Year
		int nDif = atoi(string) - m_nYear;
		if(nDif > 0){	//if increase Year
				OnNextYear();//change year
		else if(nDif < 0){	//if decrease Year
				OnPrevYear();//change Year in a calendar

This article was originally published on September 25th, 1998

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date