按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!
4
65535
CObject
4
65535
Frame3 范例程序
MFC。H
#0001 #define BOOL int
#0002 #define TRUE 1
#0003 #define FALSE 0
132
…………………………………………………………Page 195……………………………………………………………
第3章 MFC 六大關鍵技術之模擬
#0004 #define LPCSTR LPSTR
#0005 typedef char* LPSTR;
#0006 #define UINT int
#0007 #define PASCAL _stdcall
#0008
#0009 #include
#0010
#0011 class CObject;
#0012
#0013 struct CRuntimeClass
#0014 {
#0015 // Attributes
#0016 LPCSTR m_lpszClassName;
#0017 int m_nObjectSize;
#0018 UINT m_wSchema; // schema number of the loaded class
#0019 CObject* (PASCAL* m_pfnCreateObject)(); // NULL =》 abstract class
#0020 CRuntimeClass* m_pBaseClass;
#0021
#0022 // CRuntimeClass objects linked together in simple list
#0023 static CRuntimeClass* pFirstClass; // start of class list
#0024 CRuntimeClass* m_pNextClass; // linked list of registered classes
#0025 };
#0026
#0027 struct AFX_CLASSINIT
#0028 { AFX_CLASSINIT(CRuntimeClass* pNewClass); };
#0029
#0030 #define RUNTIME_CLASS(class_name)
#0031 (&class_name::class##class_name)
#0032
#0033 #define DECLARE_DYNAMIC(class_name)
#0034 public:
#0035 static CRuntimeClass class##class_name;
#0036 virtual CRuntimeClass* GetRuntimeClass() const;
#0037
#0038 #define _IMPLEMENT_RUNTIMECLASS(class_name; base_class_name; wSchema; pfnNew)
#0039 static char _lpsz##class_name'' = #class_name;
#0040 CRuntimeClass class_name::class##class_name = {
#0041 _lpsz##class_name; sizeof(class_name); wSchema; pfnNew;
#0042 RUNTIME_CLASS(base_class_name); NULL };
#0043 static AFX_CLASSINIT _init_##class_name(&class_name::class##class_name);
#0044 CRuntimeClass* class_name::GetRuntimeClass() const
#0045 { return &class_name::class##class_name; }
#0046
#0047 #define IMPLEMENT_DYNAMIC(class_name; base_class_name)
#0048 _IMPLEMENT_RUNTIMECLASS(class_name; base_class_name; 0xFFFF; NULL)
#0049
133
…………………………………………………………Page 196……………………………………………………………
第篇 勿在浮砂築高台
#0050 class CObject
#0051 {
#0052 public:
#0053 CObject::CObject() {
#0054 }
#0055 CObject::~CObject() {
#0056 }
#0057
#0058 virtual CRuntimeClass* GetRuntimeClass() const;
#0059
#0060 public:
#0061 static CRuntimeClass classCObject;
#0062 };
#0063
#0064 class CCmdTarget : public CObject
#0065 {
#0066 DECLARE_DYNAMIC(CCmdTarget)
#0067 public:
#0068 CCmdTarget::CCmdTarget() {
#0069 }
#0070 CCmdTarget::~CCmdTarget() {
#0071 }
#0072 };
#0073
#0074 class CWinThread : public CCmdTarget
#0075 {
#0076 DECLARE_DYNAMIC(CWinThread)
#0077 public:
#0078 CWinThread::CWinThread() {
#0079 }
#0080 CWinThread::~CWinThread() {
#0081 }
#0082
#0083 virtual BOOL InitInstance() {
#0084 return TRUE;
#0085 }
#0086 virtual int Run() {
#0087 return 1;
#0088 }
#0089 };
#0090
#0091 class CWnd;
#0092
#0093 class CWinApp : public CWinThread
#0094 {
#0095 DECLARE_DYNAMIC(CWinApp)
134
…………………………………………………………Page 197……………………………………………………………
第3章 MFC 六大關鍵技術之模擬
#0096 public:
#0097 CWinApp* m_pCurrentWinApp;
#0098 CWnd* m_pMainWnd;
#0099
#0100 public:
#0101 CWinApp::CWinApp() {
#0102 m_pCurrentWinApp = this;
#0103 }
#0104 CWinApp::~CWinApp() {
#0105 }
#0106
#0107 virtual BOOL InitApplication() {
#0108 return TRUE;
#0109 }
#0110 virtual BOOL InitInstance() {
#0111 return TRUE;
#0112 }
#0113 virtual int Run() {
#0114 return CWinThread::Run();
#0115 }
#0116 };
#0117
#0118 class CDocument : public CCmdTarget
#0119 {
#0120 DECLARE_DYNAMIC(CDocument)
#0121 public:
#0122 CDocument::CDocument() {
#0123 }
#0124 CDocument::~CDocument() {
#0125 }
#0126 };
#0127
#0128 class CWnd : public CCmdTarget
#0129 {
#0130 DECLARE_DYNAMIC(CWnd)
#0131 public:
#0132 CWnd::CWnd() {
#0133 }
#0134 CWnd::~CWnd() {
#0135 }
#0136
#0137 virtual BOOL Create();
#0138 BOOL CreateEx();
#0139 virtual BOOL PreCreateWindow();
#0140 };
#0141
135
…………………………………………………………Page 198……………………………………………………………
第篇 勿在浮砂築高台
#0142 class CFrameWnd : public CWnd
#0143 {
#0144 DECLARE_DYNAMIC(CFrameWnd)
#0145 public:
#0146 CFrameWnd::CFrameWnd() {
#0147 }
#0148 CFrameWnd::~CFrameWnd() {
#0149 }
#0150 BOOL Create();
#0151 virtual BOOL PreCreateWindow();
#0152 };
#0153
#0154 class CView : public CWnd
#0155 {
#0156 DECLARE_DYNAMIC(CView)
#0157 public:
#0158 CView::CView() {
#0159 }
#0160 CView::~CView() {
#0161 }
#0162 };
#0163
#0164
#0165 // global function
#0166 CWinApp* AfxGetApp()