Use the Calendar Control 8.0 as a Date Picker Control
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
}
}
}

Comments
ExCalendar
Posted by Legacy on 01/30/2002 12:00amOriginally posted by: Mike Philips
ReplyNEED HELP!!!!!!
Posted by Legacy on 04/18/2001 12:00amOriginally posted by: Nick
Can somebody send me the visual basic code for this testcalendar project..PLEASE!!!!!!!!!!!
ReplyHow to retreive the week days of the date?
Posted by Legacy on 01/13/2000 12:00amOriginally posted by: Sammy
I want to get the week day of the date, say, I want to get the "Thursday" when the picker is pointed to 13/1/2000, how to do this? Thank you!
ReplyDate picker works on some machines, but doesn't work on others?
Posted by Legacy on 08/17/1999 12:00amOriginally posted by: Erich Ruth
I really like the date picker and I incorporated it into a program I wrote. I sent the program to several different people and for some, the date picker works, but for others it doesn't work even though it was the exact same code. Are there any hardward requirements for using this code or anything I can do to determine why one computer can successfully use this code and why another computer cannot?
Please, any response you can give me will be greatly appreciated.
ReplyUse the Calendar Control 8.0 as a Date Picker Control
Posted by Legacy on 10/19/1998 12:00amOriginally posted by: Viseth Peang
ReplyMSVC++ 6.0 & COMCTL32.DLL 4.72
Posted by Legacy on 10/01/1998 12:00amOriginally posted by: Martin Rub�
Yes. VS 6.0 is shipped with MSIE 4.01 common control
library (4.72) and MFC library contains classes for
these common controls including date picker control.
Dialog editor and class wizard also support these
classes (this feature is missing in MSVC 5.0).
It has one big negative :
- I don't like 'red-circle' around the selected day.
Highlited rectangle would be better by my opinion.
Merlin.
ReplySome good remarks
Posted by Legacy on 10/01/1998 12:00amOriginally posted by: Alexey Vl
ReplyMSJ and VC6
Posted by Legacy on 09/29/1998 12:00amOriginally posted by: phil swann
I have just read the article in MSJ regarding VC6 support for latest common controls and it appears that the latest version of MFC wraps the date controls functionality
Reply