The original program and article was written by Shekar Narayanan. It allowed for the month and the date to be selected. In the updated version, the date, month and year can be selected (from the year 1583 onwards; yes it is Year 2000 compliant!!).
What is this?
This is a custom control which allows you to select a date, a month and year from a drop down window.
This custom control actually consists of two classes - one derived from CButton which acts like the regular combo box and other derived directly from generic CWnd object which is the pop-up window.
The CButton derived object is the one you would use in the dialog boxes or form views and it is called CYMSelector.
When CYMSelector receives the message 'clicked', it will create the pop-up window and disables the parent window from any activity. The user can either make the selection using the mouse or press Esc key to abort. The - and + sign at the top corners of the window allows the selection of the year.
The default color of the window is controlled by the OS's settings. Since you have the source, you could control it if you want to.
How do I use it in my project?
- Insert the YMSelector.cpp in your project and include the YMSelector.h in stdafx.h.
- Open the Dialog box or Form View resource and insert a regular button control
- Change the property of this button to Owner Draw
- From Class Wizard, create a member variable for this button - as a control.
- Open the corresponding header file and change the variable type from CButton to CYMSelector
- Alternatively, you could rebuild the .clw file by deleting it. This way, from class wizard, you can directly create the variable as CYMSelector instead of CButton, and you don't have to change the header file.
That is it. It has the following public methods to play around:
Returns the selected year as integer
Returns the selected month as integer 1 for Jan and 12 for Dec
Returns the selected month as integer from 1 to 31
Returns the selected month as string like 'January'
Sets the year value for the control. Pass a value like 1998 etc...
Sets the month value for the control. Pass between 1 and 12
Sets the date value for the control. Pass between 1 and 31