打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Macros DECLARE_DYNAMIC and DECLARE_DYNCREAT and Other
the macros DECLARE_DYNAMIC and DECLARE_DYNCREATE creates a static object within a class, which holds information about the Container class.

the macro IMPLEMENT_DYNAMIC initializes this static member as class static memebers should be initialized (out size of any function body within a c++ file).

The initialization allows MFC to check the type of objects of this class at runtime, and to check if that's a specific kind of object.

The macro DECLARE_DYNCREATE also adds a function to the class, which helps MFC creates object of this class.

The major use of the DECLARE_DYNCREATE macro, is when MFC needs to create your C++ objects.
MFC was written before your objects where written, and cannot guess you would have a CMyView class, but we want to let the MFC environment to create our view/frame/document class and tie each other up, without us doing it.

look at your CWinApp::InitInstance function and you'll see that we're passing our CRuntimeClass object (the static ones), using the RUNTIME_CLASS macro.

MFC internally uses this objects, to create our C++ objects.

There's another macro in the family BTW which also allows serialization (DECLARE_SERIAL).

use the macros as following:
DECLARE_DYNAMIC - regular classes, which you create yourself using the new operator
DECLARE_DYNCREATE - classes which MFC creates internally (you don't use the new operator) most of the time CView, CDocument, and CFrameWnd derived classes.
DECLARE_SERIAL - classes which needs to be serialized into and out of binaries.

That's all,
I also recommend your read more about macro family, and the Doc/View architecture.
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Visual C++ MFC 中常用宏的含义
DECLARE_DYNAMIC和IMPLEMENT_DYNAMIC宏
DECLARE
MFC RTTI AFX
MFC浅析(4) CObject浅析
Renaud Waldura‘s The Final Word On the final Keyword
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服