MFC動態建立物件

2021-06-03 02:38:15 字數 1489 閱讀 1824

#define implement_dyncreate(class_name, base_class_name) \

cobject* pascal class_name::createobject() \

\implement_runtimeclass(class_name, base_class_name, 0xffff, \

class_name::createobject)

#define implement_runtimeclass(class_name, base_class_name, wschema, pfnnew, class_init) \

cruntimeclass* pascal class_name::_getbaseclass() \

\afx_comdat const cruntimeclass class_name::class##class_name = ; \

cruntimeclass* pascal class_name::getthisclass() \

\cruntimeclass* class_name::getruntimeclass() const \

#define runtime_class(class_name) ((cruntimeclass*)(&class_name::class##class_name))

struct cruntimeclass

;//class_name::createobject --> pfnnew --> 建立物件的函式指標

//例子

implement_dyncreate(cview1, cformview)

=>

object* pascal cview1::createobject()

pwnd = (cwnd*)pviewclass->createobject();

///declare_dyncreate(cview1)

#define declare_dyncreate(class_name) \

declare_dynamic(class_name) \

static cobject* pascal createobject();

#define declare_dynamic(class_name) \

protected: \

static cruntimeclass* pascal _getbaseclass(); \

public: \

static const afx_data cruntimeclass class##class_name; \

virtual cruntimeclass* getruntimeclass() const; \

cobject* cruntimeclass::createobject()

cobject* pobject = null;

tryend_try

return pobject;

}

關於MFC中的動態物件建立

關於mfc中的物件動態建立 在mfc中,物件的動態建立也要依賴於rtti所建立起來的類別型錄,和動態建立有關的cruntimeclass成員有兩個 cobject pascal m pfncreateobject 指向用於建立物件的函式 cobject createobject 利用m pfncre...

MFC 動態建立Picture Control

1.首先定義乙個靜態的cstatic 的指標 cstatic ppicturecontrol null ppicturecontrol create t ws child ws visible ss bitmap,crect 20,10,80,40 this,12345 這裡在建立的時候一定不能少了...

MFC 動態建立控制項

知識點 cedit create dwstyle引數 動態建立edit控制項 crect類 一 cedit create函式 cedit create bool create dword dwstyle,const rect rect,cwnd pparentwnd,uint nid 以下風格在 e...