#include <afxwin.h> #include "resource.h" class MyDocument : public CDocument { DECLARE_DYNCREATE(MyDocument)//声明run-time类 }; IMPLEMENT_DYNCREATE(MyDocument,CDocument)//声明MyDocument为run-time类 class MyView : public CView { public: void OnDraw(CDC * aDC)//必须重载的虚函数 {} DECLARE_DYNCREATE(MyView)//声明为run-time类 }; IMPLEMENT_DYNCREATE(MyView,CView)//声明MyView为run-time类 class MyFrame:public CFrameWnd { DECLARE_DYNCREATE(MyFrame)//声明run-time类 }; IMPLEMENT_DYNCREATE(MyFrame,CFrameWnd)//声明MyFrame为run-time类 class MyApp:public CWinApp { public: BOOL InitInstance() { CDocument *doc;//指向文件的指针 CSingleDocTemplate * DocTemplate;//文件指向单文档模板对象的指针 DocTemplate = new CSingleDocTemplate( IDR_MENU1,//用于单文档框架之资源标志符 RUNTIME_CLASS(MyDocument),//单文档窗口的Document类 RUNTIME_CLASS(MyFrame),//单文档窗口的窗口框架类 RUNTIME_CLASS(MyView)//单文档窗口的View类 );//建立单文档模板对象 AddDocTemplate(DocTemplate);//将单文档模板对象设置给MyApp; doc = DocTemplate->CreateNewDocument();//建立一个新的文档 m_pMainWnd = DocTemplate->CreateNewFrame(doc,NULL);//建立一个窗口框架 DocTemplate->InitialUpdateFrame((CFrameWnd*)m_pMainWnd,doc);//初始化窗口框架并连接view m_pMainWnd->ShowWindow(SW_SHOW);//显示窗口 return true; } } a_app;//建立应用程序对象