-
June 5th, 2013, 01:20 PM
#1
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();
}
-
June 5th, 2013, 01:46 PM
#2
Re: OnPaint() not being called for CWnd
I think I figured it out. I was missing #include "afxwin.h"
-
June 5th, 2013, 11:42 PM
#3
Re: OnPaint() not being called for CWnd
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|