CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009
    Posts
    166

    OnPaint() not being called for CWnd

    Hello,

    I have a CWnd class, that is a child to another CWnd. The problem is that onPaint() is never invoked. Even when I call UpdateTest(), and the Invalidate() gets called, OnPaint() still does not get called. If I explicitly call OnPain() instead of Invalidate() it works. Anyone know what my problem is?

    Code:
    my Test.h file:
    
    #pragma once
    
    class Test : public CWnd
    {
    public:
        Test() {};
        virtual ~Test() {};
        void CreateWindow(CWnd* parent, int x, int y);
    
    private:
       	afx_msg void OnPaint();
    	DECLARE_MESSAGE_MAP()
    };
    
    
    and the cpp file:
    
    #include "Test.h"
    
    BEGIN_MESSAGE_MAP(Test, CWnd)
         ON_WM_PAINT()
    END_MESSAGE_MAP()
    
    void Test::CreateWindow(CWnd* parent, int x, int y) 
    {
    	DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER;
    	CRect rect(x, y, x+50, y+50);
    	CWnd::Create(AfxRegisterWndClass(CS_DBLCLKS), L"", dwStyle, rect, parent, NULL, NULL);
    }
    
    void Test::OnPaint() 
    {
    	CPaintDC dc(this); 
    	dc.TextOut(0, 0, "hello!");
    }
    
    void Test::UpdateTest() 
    {
        ....
        Invalidate();
    }

  2. #2
    Join Date
    Mar 2009
    Posts
    166

    Re: OnPaint() not being called for CWnd

    I think I figured it out. I was missing #include "afxwin.h"

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: OnPaint() not being called for CWnd

    Quote Originally Posted by ekhule View Post
    I think I figured it out. I was missing #include "afxwin.h"
    Please explain why and how including a certain C++ #include file during compilation fixes a runtime problem.

    I think you needed to recompile your entire application, as some object modules may not have been up to date. It has nothing to do with the include file, since include files are only there for compilation purposes, not runtime purposes.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; June 5th, 2013 at 11:47 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured