Year and Month Selector Control

year month selector image (24721 bytes)
Download Source Code and Example

The idea is for drawing the button and pop-up window is taken from Chris Maunder's contributions!

What is this?

This is a custom control which allows you to select 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?

  1. Insert the YMSelector.cpp in your project and include the YMSelector.h in stdafx.h.
  2. Open the Dialog box or Form View resource and insert a regular button control
  3. Change the property of this button to Owner Draw
  4. From Class Wizard, create a member variable for this button - as a control.
  5. Open the corresponding header file and change the variable type from CButton to CYMSelector
  6. 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:

  • GetYear()              // Returns the selected year as integer
  • GetMonth()           // Returns the selected month as integer 1 for Jan and 12 for Dec
  • GetMonthString()  // Returns the selected month as string like 'January'
  • SetYear(int)         // Sets the year value for the control. Pass a value like 1998 etc...
  • SetMonth(int)      // Sets the month value for the control. Pass between 1 and 12

 

If you have any comments or identified any bugs, please send them to me. It will help others using this control.

 

Last updated: 4 July 1998



Comments

  • make sense

    Posted by Legacy on 05/10/2002 12:00am

    Originally posted by: sutony

    thank you,
    it's make sense when someone want to select month
    rather than day. so it's no reason to resort
    ms's monthview of monthpickerview

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • VMware vCloud® Government Service provided by Carpathia® is an enterprise-class hybrid cloud service that delivers the tried and tested VMware capabilities widely used by government organizations today, with the added security and compliance assurance of FedRAMP authorization. The hybrid cloud is becoming more and more prevalent – in fact, nearly three-fourths of large enterprises expect to have hybrid deployments by 2015, according to a recent Gartner analyst report. Learn about the benefits of …

Most Popular Programming Stories

More for Developers

RSS Feeds