Use the Calendar Control 8.0 as a Date Picker Control | CodeGuru

Use the Calendar Control 8.0 as a Date Picker Control

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Sep 25, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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
			while(nDif–)
				OnNextYear();//change year
		}
		else if(nDif < 0){	//if decrease Year
			while(nDif++)
				OnPrevYear();//change Year in a calendar
		}
	}

}

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.