vc++技术内幕(第四版)笔记(第8章)(5)
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(),"C:WINDOWSsystem32MSCAL.hlp",
HELP_FINDER,0);
return FALSE;
}
7,在运行时创建ActiveX控件:
1)在项目中插入ActiveX控件。ClassWizard会生存相应的ActiveX控件类的文件。
2)在使用ActiveX控件的对话框或窗口类中添加ActiveX控件类数据成员。
3)重写CDialog::OnInitDialog(或其它窗口中响应WM_CREAT消息),在新的函数中调用ActiveX控件类Create函数。
4)在父窗口类中,手工添加必要的与新控件有关的事件消息处理函数及原型,和相应的消息映射。
8,更多的ActiveX控件编程参见P160-167页(ActiveX控件在HTML文件中使用 和 在运行时创建ActiveX控件)。
- 上一篇:vc++中进程与多进程管理的方法
- 下一篇:vc++技术内幕(第四版)笔记(第7章)