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.
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。