VC++技术内幕(windows编程篇)(11)
原型:CDataExchange::CDataExchange(CWnd* pDlgWnd, BOOL bSaveAndValidate);
定义:
CDataExchange::CDataExchange(CWnd* pDlgWnd, BOOL bSaveAndValidate) {
ASSERT_VALID(pDlgWnd);
m_bSaveAndValidate = bSaveAndValidate; m_pDlgWnd = pDlgWnd; m_hWndLastControl = NULL; }
//其中m_pDlgWnd和m_bSaveAndValidate是CDataExchange数据成员,可以通过这中方式给它们赋值。
m_pDlgWnd:The dialog box or window where the data exchange takes place. m_bSaveAndValidate Flag for the direction of DDX and DDV. 详见说明二。 说明二:
//CDataExchange does not have a base class.
//The CDataExchange class supports the dialog data exchange (DDX) and dialog data validation (DDV) routines used by the Microsoft Foundation classes. Use this class if you are writing data exchange routines for custom data types or controls, or if you are writing your own data validation routines.
//A CDataExchange object provides the context information needed for DDX and DDV to take place. The flag m_bSaveAndValidate is FALSE when DDX is used to fill the initial values of dialog controls from data members. The flag m_bSaveAndValidate is TRUE when DDX is used to set the current values of dialog controls into data members and when DDV is used to validate the data values. If the DDV validation fails, the DDV procedure will display a message box explaining the input error. The DDV procedure will then call Fail to reset the focus to the offending control and throw an exception to stop the validation process.
代码二:(是为了比较代码一做些说明的)
void CActiveXDialog::DoDataExchange(CDataExchange* pDX) {
CDialog::DoDataExchange(pDX);//调用基类的DoDataExchange //{{AFX_DATA_MAP(CActiveXDialog)
DDX_Control(pDX, IDC_CALENDAR1, m_calendar); DDX_Text(pDX, IDC_DAY, m_sDay); DDX_Text(pDX, IDC_MONTH, m_sMonth); DDX_Text(pDX, IDC_YEAR, m_sYear); //}}AFX_DATA_MAP } 说明一:
//DoDataExchange Called by the framework to exchange and validate dialog data. //DoDataExchange Never call this function directly. It is called by the UpdateData member function. Call UpdateData to initialize a dialog box‘s controls or retrieve data from a dialog box.
说明二:
//在MFC|SRC|WINCORE.CPP文件中可以看到UpdateData函数的定义 BOOL CWnd::UpdateData(BOOL bSaveAndValidate) { ...
CDataExchange dx(this, bSaveAndValidate);//创建了一个CDataExchange对象,与当前窗口相关联
...
DoDataExchange(&dx); //注意:DoDataExchange是个虚函数。子类中如果有重写了,则调用子类的。
... }
说明三:
//在MFC|Include|AFXWIN2.INL文件中可有看到CWnd::DoDataExchange的如下定义(内联):
// CWnd dialog data support
_AFXWIN_INLINE void CWnd::DoDataExchange(CDataExchange*) { } // default does nothing
由此可见代码二中CDialog::DoDataExchange(pDX)调用好象是个?摆设‘,不起做任何事情。框架设置DoDataExchange函数目的是在我们子窗口类(这里是对话筐)中重写它,添加代码完成子窗口类(这里是对话筐)中数据成员与对话筐上控件的交互。
说明四:
如果结合UpdateData和DoDataExchange两函数整体来看,应该体会到这里代码一与代码二实质上是一会事情。代码二只是借助了框架兜了些圈子。
说明四:
摘录MSDN中Dialog Data Exchange一些E文段落对上讨论做个总结: Dialog Data Exchange
If you use the DDX mechanism, you set the initial values of the dialog object‘s member variables, typically in your OnInitDialog handler or the dialog constructor. Immediately before the dialog is displayed, the framework‘s DDX mechanism transfers the values of the member variables to the controls in the dialog box, where they appear when the dialog box itself appears in response to DoModal or Create. The default implementation of OnInitDialog in CDialog calls the UpdateData member function of class CWnd to initialize the controls in the dialog box.
The same mechanism transfers values from the controls to the member variables when the user clicks the OK button (or whenever you call the UpdateData member
function with the argument TRUE). The dialog data validation mechanism validates any data items for which you specified validation rules.
UpdateData works in both directions, as specified by the BOOL parameter passed to it. To carry out the exchange, UpdateData sets up a CDataExchange object and calls your dialog class‘s override of CDialog‘s DoDataExchange member function.
DoDataExchange takes an argument of type CDataExchange. The CDataExchange object
passed to UpdateData represents the context of the exchange, defining such information as the direction of the exchange.
When you (or ClassWizard) override DoDataExchange, you specify a call to one DDX function per data member (control). Each DDX function knows how to exchange data in both directions based on the context supplied by the CDataExchange argument passed to your DoDataExchange by UpdateData.
MFC provides many DDX functions for different kinds of exchange.
If the user cancels a modal dialog box, the OnCancel member function terminates the dialog box and DoModal returns the value IDCANCEL. In that case, no data is exchanged between the dialog box and the dialog object.
9)当输入焦点在某ActiveX控件上时,按下F1键引起OnHelpInfo函数调用,可在OnHelpInfo函数中设置帮助信息。
说明:
ClassWizard不能修改生成的ActiveX控件类,因而必须手工加入消息映射代码。事例代码如下:
//在ActiveX控件类头文件中加入函数原型并声明消息映射表: protected:
afx_msg BOOL OnHelpInfo(HELPINFO* pHelpInfo);
DECLARE_MESSAGE_MAP()//在ActiveX控件类代码文件中添加消息映射及OnHelpInfo函数定义:
BEGIN_MESSAGE_MAP(CCalendar,CWnd) ON_WM_HELPINFO() END_MESSAGE_MAP() /**
BOOL CCalendar::OnHelpInfo(HELPINFO *pHelpInfo) {
::WinHelp(GetSafeHwnd(),\ HELP_FINDER,0);
…… 此处隐藏:3160字,全部文档内容请下载后查看。喜欢就下载吧 ……相关推荐:
- [学前教育]MC9S12XS256RMV1 xs128芯片手册4
- [学前教育]安东尼语录经典语录
- [学前教育]e级gps控制测量技术设计书
- [学前教育]苏教版2022-2022学年八年级下学期期末
- [学前教育]装修公司推广 营销
- [学前教育]家政服务合同(完整版)
- [学前教育]湖北省2016届高三联考语文试题
- [学前教育]爱立信无涯学习系统LTE题库1-LTE基础知
- [学前教育]揭秘大众柴油车作弊软件原理
- [学前教育]人才流失原因及对策分析
- [学前教育]房屋建筑施工工程劳务分包合同
- [学前教育]国际贸易实务试卷A卷09.6
- [学前教育]校园废品回收活动计划方案书范文格
- [学前教育]电大成本会计试题及答案
- [学前教育]大学物理实验 华南理工出版社 绪论答案
- [学前教育]爱丁堡产后抑郁量表
- [学前教育]液压冲击的危害、产生原因与防止方法(
- [学前教育]学生工作总结高一学生期中考试总结_020
- [学前教育]人民医院医疗废物管理规章制度大全
- [学前教育]阳光维生素的巨大抗癌潜能阅读题答案.d
- 马云在云锋基金江苏论坛闭幕式的发言
- 试论小学体育教育中的心理健康教育-教
- 语文A版一年级下册《语文乐园一》教学
- 2021四川大学物理化学考研真题经验参考
- [人教A版]2015-2016学年高中数学 第二
- 终端网点销售返利协议书
- 江苏省2015年眼科学主治医师青光眼考试
- 2017年部编人教版八年级语文上册教案
- 十一中学七年级英语上册Unit7Howmuchar
- 以赛促教的创新性实验教学机制建设实践
- 平凉市崆峒区2015七年级下生物期末试题
- 琶洲(地块五)A、B塔楼1、2#塔吊基础
- 一级医院工作制度与人员岗位职责
- 2018北京西城区高三二模理科数学试题及
- 炒股密码线技术 - 图文
- 职高学生生涯发展辅导教案
- 语文人教版四年级上册8 世界地图引出的
- 最新最新人教版二年级上册全册数学教案
- 2017高考英语全国2卷精彩试题(有问题
- 普通心理学笔记




