Click here to Skip to main content
15,905,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. I'm using Date-Time picker control. One for Date and one for Time. I'm catching
C++
DTN_DATETIMECHANGE
very easy when change date or time. But I need to call some handler before Time or Date will change in control.I need to get old value before new value.
Thanks
Posted
Comments
Jochen Arndt 16-Apr-13 7:41am    
Because you did not know when a user changes the value, you can't get the value immediately before it is changed (there is no kind of DTN_BEFORECHANGE handler). All you can do is adding a member variable that holds the old value. Set it to the initial value when the controls has been created and update it when necessary (e.g. when calling SetTime(), inside your DTN_DATETIMECHANGE handler, or when leaving a parent dialog with OK).
thomas_wingfield 16-Apr-13 7:49am    
:(Thanks man I will do it like u said.But It's will be still open, probably somebody will give me better solution
Coder Block 16-Apr-13 8:57am    
Actually jochen is right,in mfc never store previous selected values of any control.you will never find it in even combo box.
So better way and its easy too,Store current selection of date and time cotrol in some variable say pqr and for next change of date and time you consider previous stored variable as last selected date.

1 solution

I agree with the comments, you need to store the orignal data used to set the initial state of the control yourself and then track DTN_DATETIMECHANGE notifications as you are doing.

In general storing data in controls is not a good idea and in a way it's a pity that Windows allows it and MFC encourages it. For the reasons why it's not a good idea search on MVC, Model View Controller. This is the OOP based concept on which MFC is supposed to be based but it is in my opinion a very poor implementation of MVC.

For a simple insight consider this: What if you needed to have 2 different Date Time controls on 2 separate displays showing the same date, for example a public timetable board and a live management console?
Consider all the extra work that is involved in that scenario when the data is stored in the control compared with when the control is just a View of the data.

I hope this helps you see why you don't really have a code problem it's just that MFC's poor design has given you false expectations of how you should be working.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900