// MFCView.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "resource.h" class CMyView:public CView{ public: virtual void OnDraw(CDC *pDC); DECLARE_MESSAGE_MAP() public: afx_msg void OnTest(); afx_msg void OnPaint(); }; BEGIN_MESSAGE_MAP(CMyView,CView) ON_WM_PAINT() ON_COMMAND(ID_TEST,OnTest) END_MESSAGE_MAP() void CMyView::OnTest(){ AfxMessageBox("OnTest"); } void CMyView::OnPaint(){ PAINTSTRUCT ps={0}; HDC hDC=::BeginPaint(m_hWnd,&ps); TextOut(hDC,100,100,"View",4); ::EndPaint(m_hWnd,&ps); } void CMyView::OnDraw(CDC *pDC){ } class MCFViewFrame:public CFrameWnd{ DECLARE_MESSAGE_MAP() public: afx_msg int OnCreate(LPCREATESTRUCT lpCreate); public: CMyView *m_wndView; }; BEGIN_MESSAGE_MAP(MCFViewFrame,CFrameWnd) ON_WM_CREATE() END_MESSAGE_MAP() int MCFViewFrame::OnCreate(LPCREATESTRUCT lpCreate) { CFrameWnd::OnCreate(lpCreate); m_wndView=new CMyView(); //AFX_IDW_PANE_FIRST 默认的ID号 填充整个窗口 m_wndView->Create(NULL,"View", WS_CHILD|WS_VISIBLE|WS_BORDER,CRect(100,100,200,200),this, AFX_IDW_PANE_FIRST); return 1; } class CViewApp:public CWinApp{ public: virtual BOOL InitInstance(); }; CViewApp theApp; BOOL CViewApp::InitInstance(){ MCFViewFrame *pWin=new MCFViewFrame(); pWin->Create(NULL,"ViewApp",WS_OVERLAPPEDWINDOW, CFrameWnd::rectDefault,NULL,MAKEINTRESOURCE(IDR_MAINFRM)); m_pMainWnd=pWin; m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); return 1; }