我是MFC的新手,并且未调用以下代码OnPaint()
。
//TestWnd.H
#ifndef TESTWND
#define TESTWND
#include<afxwin.h>
//window
class TestWnd:public CFrameWnd
{
public:
TestWnd();
protected:
afx_msg void onPaint();
DECLARE_MESSAGE_MAP()
};
#endif
//TestWnd.cpp
#include"TestWnd.h"
TestWnd::TestWnd()
{
Create (NULL, _T ("The Hello Application"),
WS_OVERLAPPEDWINDOW,
CRect(120, 100, 700, 480), NULL);
}
void TestWnd ::onPaint()
{
MessageBox(_T("The window has been PAINTED!!!"));
//CPaintDC dc(this);
//CRect crec;
//GetClientRect(&crec);
//dc.DrawText(_T("Hello"),-1, &crec, DT_SINGLELINE/* | DT_CENTER | DT_VCENTER*/);
}
BEGIN_MESSAGE_MAP(TestWnd,CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
//TestApp.h
#ifndef TESTAPP
#define TESTAPP
#include<afxwin.h>
class TestApp:public CWinApp
{
public:
virtual BOOL InitInstance();
};
#endif
//TestApp.cpp
#include "TestApp.h"
#include "TestWnd.h"
TestApp g_obj;
BOOL TestApp::InitInstance()
{
m_pMainWnd = new TestWnd;
m_pMainWnd->ShowWindow(m_nCmdShow);
//m_pMainWnd->UpdateWindow();
return TRUE;
}
答案 0 :(得分:0)
原因很简单。
ON_WM_PAINT
需要名为OnPaint
的处理程序。您实现了一个名为onPaint
的处理程序。由于存在默认实现,因此调用默认的CFrameWnd::OnPaint
。
将处理程序重命名为OnPaint
。