Use the Date/Time Picker common control (2)

I just read the article "Use the Date/Time Picker common control (IE3+)" and now I'll try to explain my code.

I want to use only MFC interface for all my applications,then when MFC doesn't wrap some API and I want to use it,I write a MFC class.

In the article I just read,I see a GOOD IDEA for use Data/Time Picker but If you have a MFC class you can have a self control that has more feature . I wrote a MFC class that wrap Date Picker Control (no Time picker for now) that allows you

A) RANGE VALIDATION SUPPORT
B) EMPTY VALUE SUPPORT (CHECK BOX)
C) Auto InitCommonControlsEx
D) Data changing notifycation

Construction:

1. The default contructor assigns the current date.
CBaseDataPk();

2.SetRange - this method assign dt1 current value and a range from dt1 to dt2 (I want use only MFC class)

	SetRange(COleDateTime* dt1,COleDateTime* dt2);

3. SetRange - this method assign current date value and a range from < dayback > back to < dayafter > forward
SetRange(365,0) from a year ago to today;
SetRange(1,1) from yesterday to tomorrow;

	SetRange(int dayback,int dayafter);

4. You don't need data exchange the control provide it when you need the value you have a COleDateTime Value with the method GetCurDate(),it dosn't matter if the there are a window on not.

5. the subclassing method is

BOOL  SetData(UINT idc,CWnd* parent,BOOL empty = TRUE,BOOL updown = FALSE);
WHERE
idc is the static control yo've placed in the dialog parent is the dialog object
empty = TRUE empty value is allowed (check box)
updown = TRUE updown style

To use the control

1. Put a static control in your dialog for each data picker control you need
CBaseDataPk m_pk1;
CBaseDataPk m_pk2;

2. in the InitDialog put this code
  m_pk1.SetRange(60,0);  // from 60 days back to today
  m_pk1.SetData(IDC_DATAPK1,this); // subclass1
  m_pk2.SetRange(1,1); // from yesterday to tomorrow
  m_pk2.SetData(IDC_DATAPK2,this); // subclass2 ,FALSE,TRUE);

UPDATE #1:

I wrote some update to Date Picker Class :

In the new implementation you can now

1) Easily test null value through IsNullDate() method

2) Initial Null Value through new implementation of SetRange methods

void SetRange(COleDateTime* dt1,COleDateTime* dt2,BOOLnulvalue=FALSE,BOOL updatecurvalue = TRUE);
void SetRange(int dayback,int dayafter,BOOL nullvalue =FALSE,BOOL updatecurvalue = TRUE);

3) Buddy Support. New methods are

	CBaseDataPk* GetBuddy() { return m_pDataBuddy; }
	void SetBuddy(CBaseDataPk* p) {  m_pDataBuddy = p; }

The Buddy support allow you to have another CBaseDatePk control that changes his range dynamically when the first (master) CBaseDatePk changes his value.

To use Buddy feature in the InitDialog put this code:

  m_pk2.SetData(IDC_DATAPK2,this); 
  m_pk1.SetRange(60,5,TRUE);  // FROM 60 DAYS BACK TO 5 DAYS FORWARD ,initial null value
  m_pk1.SetBuddy(&m_pk2);  // m_pk1 master m_pk2 slave
  m_pk1.SetData(IDC_DATAPK1,this);

the master m_pk1 changes the range of m_pk2 when his value changes so you'll be sure that the date of m_pk1 is always < of m_pk2 if you uncheck box (null value) from m_pk1 then m_pk2 becomes unchecked at last if only m_pk2 has a good value then m_pk1 has the same value.

Download Project. 51KB



Comments

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

Top White Papers and Webcasts

  • Do you know where your data is? Consumer cloud-based file sharing services store your sensitive company data on servers outside of your control, outside of your policy and regulatory guidelines – maybe even outside your country – and not managed by you. The potential for data leakage, security breaches, and harm to your business is enormous. Download this white paper to learn about file sync and share alternatives that allow you to manage and protect your sensitive data while integrating and …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds