八宝书库 > 文学其他电子书 > 深入浅出MFC第2版(PDF格式) >

第39部分

深入浅出MFC第2版(PDF格式)-第39部分

小说: 深入浅出MFC第2版(PDF格式) 字数: 每页4000字

按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!






                  enter a class name。。。  CView 

                  Error: Trying to create object which is not DECLARE_DYNCREATE 

                  or DECLARE_SERIAL: CView。 



                  enter a class name。。。  CMyView 

                  CWnd Constructor 

                  CMyView Constructor 

                  Hello CMyView 



                  enter a class name。。。  CMyFrameWnd 

                  CWnd Constructor 

                  CFrameWnd Constructor 

                  CMyFrameWnd Constructor 

                  Hello CMyFrameWnd 



                  enter a class name。。。  CMyDoc 

                  CMyDoc Constructor 

                  Hello CMyDoc 



150 


…………………………………………………………Page 213……………………………………………………………

                                                      第3章    MFC 六大關鍵技術之模擬 



      enter a class name。。。  CWinApp 

      Error: Trying to create object which is not DECLARE_DYNCREATE 

      or DECLARE_SERIAL: CWinApp。 



      enter a class name。。。 CJjhou  (故意输入一个不在「类别型录网」中的类别名称) 



      Error: Class not found: CJjhou  (程序结束) 



Frame6  范例程序 



      MFC。H 



      #0001  #define BOOL int 

      #0002  #define TRUE 1 

      #0003  #define FALSE 0 

      #0004  #define LPCSTR  LPSTR 

      #0005  typedef char*   LPSTR; 

      #0006  #define UINT int 

      #0007  #define PASCAL _stdcall 

      #0008  #define TRACE1 printf 

      #0009 

      #0010  #include  

      #0011  #include  

      #0012  #include  

      #0013 

      #0014  class CObject; 

      #0015 

      #0016  struct CRuntimeClass 

      #0017  { 

      #0018  // Attributes 

      #0019     LPCSTR m_lpszClassName; 

      #0020     int m_nObjectSize; 

      #0021     UINT m_wSchema; // schema number of the loaded class 

      #0022     CObject* (PASCAL* m_pfnCreateObject)(); // NULL =》 abstract class 

      #0023     CRuntimeClass* m_pBaseClass; 

      #0024 

      #0025     CObject* CreateObject(); 

      #0026     static CRuntimeClass* PASCAL Load(); 

      #0027 

      #0028     // CRuntimeClass objects linked together in simple list 

      #0029     static CRuntimeClass* pFirstClass; // start of class list 

      #0030     CRuntimeClass* m_pNextClass;    // linked list of registered classes 

      #0031  }; 

      #0032 

      #0033  struct AFX_CLASSINIT 



                                                                                       151 


…………………………………………………………Page 214……………………………………………………………

                    第篇  勿在浮砂築高台 



                    #0034          { AFX_CLASSINIT(CRuntimeClass* pNewClass); }; 

                    #0035 

                    #0036  #define RUNTIME_CLASS(class_name)  

                    #0037          (&class_name::class##class_name) 

                    #0038 

                    #0039  #define DECLARE_DYNAMIC(class_name)  

                    #0040  public:  

                    #0041          static CRuntimeClass class##class_name;  

                    #0042          virtual CRuntimeClass* GetRuntimeClass() const; 

                    #0043 

                    #0044  #define DECLARE_DYNCREATE(class_name)  

                    #0045          DECLARE_DYNAMIC(class_name)  

                    #0046          static CObject* PASCAL CreateObject(); 

                    #0047 

                    #0048  #define _IMPLEMENT_RUNTIMECLASS(class_name; base_class_name; wSchema; pfnNew)  

                    #0049          static char _lpsz##class_name'' = #class_name;  

                    #0050          CRuntimeClass class_name::class##class_name = {  

                    #0051                  _lpsz##class_name; sizeof(class_name); wSchema; pfnNew;  

                    #0052                          RUNTIME_CLASS(base_class_name); NULL };  

                    #0053          static AFX_CLASSINIT _init_##class_name(&class_name::class##class_name);  

                    #0054          CRuntimeClass* class_name::GetRuntimeClass() const  

                    #0055                  { return &class_name::class##class_name; }  

                    #0056 

                    #0057  #define IMPLEMENT_DYNAMIC(class_name; base_class_name)  

                    #0058          _IMPLEMENT_RUNTIMECLASS(class_name; base_class_name; 0xFFFF; NULL) 

                    #0059 

                    #0060  #define IMPLEMENT_DYNCREATE(class_name; base_class_name)  

                    #0061          CObject* PASCAL class_name::CreateObject()  

                    #0062                  { return new class_name; }  

                    #0063          _IMPLEMENT_RUNTIMECLASS(class_name; base_class_name; 0xFFFF;  

                    #0064                  class_name::CreateObject) 

                    #0065 

                    #0066  class CObject 

                    #0067  { 

                    #0068  public: 

                    #0069    CObject::CObject()  { 

                    #0070                           } 

                    #0071    CObject::~CObject() { 

                    #0072                            } 

                    #0073 

                    #0074    virtual CRuntimeClass* GetRuntimeClass() const; 

                    #0075    BOOL IsKindOf(const CRuntimeClass* pClass) const; 

                    #0076 

                    #0077  public: 

                    #0078    static CRuntimeClass classCObject; 

                    #0079    virtual void SayHello() { cout 

返回目录 上一页 下一页 回到顶部 0 0

你可能喜欢的