不调用TestWnd :: OnPaint()

时间:2015-11-29 15:32:21

标签: mfc

我是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;
        }

1 个答案:

答案 0 :(得分:0)

原因很简单。

ON_WM_PAINT需要名为OnPaint的处理程序。您实现了一个名为onPaint的处理程序。由于存在默认实现,因此调用默认的CFrameWnd::OnPaint

将处理程序重命名为OnPaint