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();
}
Re: OnPaint() not being called for CWnd
I think I figured it out. I was missing #include "afxwin.h"
Re: OnPaint() not being called for CWnd
Quote:
Originally Posted by
ekhule
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