/* MENUITEM "Exit2", ID_APP_EXIT(执行退出命令) */ #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) }; IMPLEMENT_DYNCREATE(MyView, CView) class MyFrame:public CFrameWnd { DECLARE_DYNCREATE(MyFrame) }; IMPLEMENT_DYNCREATE(MyFrame, CFrameWnd) 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; } }; MyApp a_app; //建立应用程序