VC

MFC Library Reference

IMPLEMENT_DYNCREATE

Enables objects of CObject-derived classes to be created dynamically at run time when used with the DECLARE_DYNCREATE macro.

 
IMPLEMENT_DYNCREATE(class_name, base_class_name )
class_name

The actual name of the class.

base_class_name

The actual name of the base class.

The framework uses this ability to create new objects dynamically, for example, when it reads an object from disk during serialization. Add the IMPLEMENT_DYNCREATE macro in the class implementation file. For more information, see CObject Class Topics.

If you use the DECLARE_DYNCREATE and IMPLEMENT_DYNCREATE macros, you can then use the RUNTIME_CLASS macro and the CObject::IsKindOf member function to determine the class of your objects at run time.

If DECLARE_DYNCREATE is included in the class declaration, then IMPLEMENT_DYNCREATE must be included in the class implementation.

Note that this macro definition will invoke the default constructor for your class. If a non-trivial constructor is explicitly implemented by the class, it must also explicitly implement the default constructor as well. The default constructor can be added to the class's private or protected member sections to prevent it from being called from outside the class implementation.

Visual C++
class CMyDynCreateObj : public CObject { int m_Num; public: DECLARE_DYNCREATE(CMyDynCreateObj) CMyDynCreateObj( int Num) { m_Num = Num; } private: CMyDynCreateObj() { m_Num = 0; } // provide default constructor only for // dynamic creation };
Visual C++
IMPLEMENT_DYNCREATE(CMyDynCreateObj, CObject)

Header     File:   afxmt.h

BEGIN_MESSAGE_MAP( theClass, baseClass )

Parameters

theClass

Specifies the name of the class whose message map this is.

baseClass

Specifies the name of the base class of theClass.

Remarks

Use the BEGIN_MESSAGE_MAP macro to begin the definition of your message map.
使用 BEGIN_MESSAGE_MAP宏来开始你的消息映射的定义。由此可知, BEGIN_MESSAGE_MAP只是一个宏定义,其目的是为了简化代码的编写。

In the implementation (.CPP) file that defines the member functions for your class, start the message map with the BEGIN_MESSAGE_MAP macro, then add macro entries for each of your message-handler functions, and complete the message map with the END_MESSAGE_MAP macro.
在中定义了类的成员函数的实现文件(.cpp文件)中,用BEGIN_MESSAGE_MAP 宏开始消息映射,然后为每一个消息句柄函数添加宏变量,用 END_MESSAGE_MAP宏完成消息映射。

Example

// example for BEGIN_MESSAGE_MAP BEGIN_MESSAGE_MAP( CMyWindow, CFrameWnd ) //{{AFX_MSG_MAP( CMyWindow )    ON_WM_PAINT() //该消息映射宏主要是将OnPaint()函数与应用程序框架联系在一起。    ON_COMMAND( IDM_ABOUT, OnAbout ) //}}AFX_MSG_MAP END_MESSAGE_MAP( )

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值