如何捕获更改日期时间选择器控制MFC的事件? [英] How catch event of changing on Date Time picker control MFC?

查看:197
本文介绍了如何捕获更改日期时间选择器控制MFC的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我正在使用Date-Time选择器控件。一个用于日期,一个用于时间。在更改日期或时间时,我很容易抓住

 DTN_DATETIMECHANGE 

。但是我需要在Time或Date之前调用一些处理程序来控制。我需要在新值之前获取旧值。

谢谢

解决方案

< blockquote>我同意这些评论,你需要存储用于自己设置控件初始状态的orignal数据,然后跟踪DTN_DATETIMECHANGE通知。



一般情况下,在控件中存储数据并不是一个好主意,在某种程度上,Windows允许它并且MFC鼓励它是一种遗憾。出于这个原因,为什么搜索 MVC ,模型视图控制器并不是一个好主意。这是基于OOP的概念,MFC应该基于该概念,但在我看来,MVC的实现非常糟糕。



对于一个简单的见解,请考虑以下因素:如果您需要在2个显示相同日期的独立显示屏上设置2个不同的日期时间控件,例如公共时间表板和实时管理控制台,该怎么办?

当控件只是数据视图时,考虑数据存储在控件中时所涉及的所有额外工作。



我希望这可以帮助你了解为什么你真的没有代码问题只是因为MFC的糟糕设计让你误以为你应该如何工作。

Hello. I''m using Date-Time picker control. One for Date and one for Time. I''m catching

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

解决方案

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.


这篇关于如何捕获更改日期时间选择器控制MFC的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆