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

第40部分

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

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

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






154 


…………………………………………………………Page 217……………………………………………………………

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



#0172    BOOL Create(); 

#0173    virtual BOOL PreCreateWindow(); 

#0174    void SayHello() { cout m_pNextClass = CRuntimeClass::pFirstClass; 

#0015          CRuntimeClass::pFirstClass = pNewClass; 

#0016  } 

#0017 

#0018  CObject* CRuntimeClass::CreateObject() 

#0019  { 

#0020          if (m_pfnCreateObject == NULL) 

#0021          { 

#0022                  TRACE1(〃Error: Trying to create object which is not 〃 

#0023                           〃DECLARE_DYNCREATE nor DECLARE_SERIAL: %hs。n〃; 

#0024                           m_lpszClassName); 

#0025                  return NULL; 

#0026          } 



                                                                                         155 


…………………………………………………………Page 218……………………………………………………………

                   第篇  勿在浮砂築高台 



                   #0027 

                   #0028          CObject* pObject = NULL; 

                   #0029          pObject = (*m_pfnCreateObject)(); 

                   #0030 

                   #0031          return pObject; 

                   #0032  } 

                   #0033 

                   #0034  CRuntimeClass* PASCAL CRuntimeClass::Load() 

                   #0035  { 

                   #0036          char szClassName'64'; 

                   #0037          CRuntimeClass* pClass; 

                   #0038 

                   #0039          // JJHOU : instead of Load from file; we Load from cin。 

                   #0040          cout 》 szClassName; 

                   #0042 

                   #0043          for (pClass = pFirstClass; pClass != NULL; pClass = pClass…》m_pNextClass) 

                   #0044          { 

                   #0045                  if (strcmp(szClassName; pClass…》m_lpszClassName) == 0) 

                   #0046                          return pClass; 

                   #0047          } 

                   #0048 

                   #0049          TRACE1(〃Error: Class not found: %s n〃; szClassName); 

                   #0050          return NULL; // not found 

                   #0051  } 

                   #0052 

                   #0053  CRuntimeClass* CObject::GetRuntimeClass() const 

                   #0054  { 

                   #0055          return &CObject::classCObject; 

                   #0056  } 

                   #0057 

                   #0058  BOOL CObject::IsKindOf(const CRuntimeClass* pClass) const 

                   #0059  { 

                   #0060          CRuntimeClass* pClassThis = GetRuntimeClass(); 

                   #0061          while (pClassThis != NULL) 

                   #0062          { 

                   #0063                  if (pClassThis == pClass) 

                   #0064                          return TRUE; 

                   #0065                  pClassThis = pClassThis…》m_pBaseClass; 

                   #0066          } 

                   #0067          return FALSE;       // walked to the top; no match 

                   #0068  } 

                   #0069 

                   #0070  BOOL CWnd::Create() 

                   #0071  { 

                   #0072    return TRUE; 



156 


…………………………………………………………Page 219……………………………………………………………

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



#0073  } 

#0074 

#0075  BOOL CWnd::CreateEx() 

#0076  { 

#0077    PreCreateWindow(); 

#0078    return TRUE; 

#0079  } 

#0080 

#0081  BOOL CWnd::PreCreateWindow() 

#0082  { 

#0083    return TRUE; 

#0084  } 

#0085 

#0086  BOOL CFrameWnd::Create() 

#0087  { 

#0088    CreateEx(); 

#0089    return TRUE; 

#0090  } 

#0091 

#0092  BOOL CFrameWnd::PreCreateWindow() 

#0093  { 

#0094    return TRUE; 

#0095  } 

#0096 

#0097  CWinApp* AfxGetApp() 

#0098  { 

#0099    return theApp。m_pCurrentWinApp; 

#0100  } 

#0101 

#0102  IMPLEMENT_DYNAMIC(CCmdTarget; CObject) 

#0103  IMPLEMENT_DYNAMIC(CWinThread; CCmdTarget) 

#0104  IMPLEMENT_DYNAMIC(CWinApp; CWinThread) 

#0105  IMPLEMENT_DYNAMIC(CDocument; CCmdTarget) 

#0106  IMPLEMENT_DYNCREATE(CWnd; CCmdTarget) 

#0107  IMPLEMENT_DYNAMIC(CView; CWnd) 

#0108  IMPLEMENT_DYNCREATE(CFrameWnd; CWnd) 



MY。H 



#0001  #include  

#0002  #include 〃mfc。h〃 

#0003 

#0004  class CMyWinApp : public CWinApp 

#0005  { 

#0006  public: 

#0007    CMyWinApp::CMyWinApp()   { 



                                                                                 157 


…………………………………………………………Page 220……………………………………………………………

                    第篇  勿在浮砂築高台 



                    #0008                                  } 

                    #0009    CMyWinApp::~CMyWinApp()  { 

                    #0010                                  } 

                    #0011 

                    #0012    virtual BOOL InitInstance(); 

                    #0013  }; 

                    #0014 

                    #0015  class CMyFrameWnd : public CFrameWnd 

                    #0016  { 

                    #0017          DECLARE_DYNCREATE(CMyFrameWnd) 

                    #0018  public: 

                    #0019    CMyFrameWnd(); 

                    #0020    ~CMyFrameWnd()  { 

                    #0021                       } 

                    #0022    void SayHello() { cout 

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

你可能喜欢的