江门市获国家森林城市:C++中,把OnPaint添加到CMFCWindow类中?

来源:百度文库 编辑:神马品牌网 时间:2024/03/29 21:09:52
//MFCWindow.h

class CMFCApp:public CWinApp
{
public:
virtual BOOL InitInstance();
};
class CMFCWindow:public CFrameWnd
{
public:
CMFCWindow();
protected:
afx_msg void OnOaint();
DECLARE_MESSAGE_MAP()
};

//MFCWindow.cpp

#include<afxwin.h>
#include"MFCWindow.h"
CMFCApp mfcApp;
BOOL CMFCApp::InitInstance()
{
m_pMainWnd=new CMFCWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CMFCWindow,CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
CMFCWindow::CMFCWindow()
{
Create(NULL,_T("七夕"));
}
void CMFCWindow::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.DrawText(_T("盈盈一水间,脉脉不得语"),-1,&rect,
DT_SINGLELINE|DT_CENTER|DT_VCENTER);
}

编译后出现error C2509: 'OnPaint' : member function not declared in 'CMFCWindow'
d:\msdev98\myprojects\7311\da\mfcwindow.h(6) : see declaration of 'CMFCWindow'
怎么解决?

你把OnPaint打成OnOaint了。

在视图类里响应,就是View里面。