I want to write a control inherit from CWnd,what should I do if I want to create it? I call the function CWnd::create(),but it fails.Please give me a instance.
thanks for your help,this link is useful . I have an other problem.I use CDC in OnPaint() function.but Endless loop happen.
I don't know why,could you help me?thanks.
the code is like this:
CRect rect; //begin
GetClientRect(rect);
CDC dc;
CBrush brush;
COLORREF color=RGB(155,155,155);
brush.CreateSolidBrush(color);
dc.FillRect(&rect,&brush);//if break point come to here,it will go to begin. the program can not go down.
brush.DeleteObject();
dc.DeleteDC();
if break point come to here,it will go to begin. the program can not go down.
The problem is the break point: if you continue after the break point the window must refresh (hence OnPaint() is called) because it was hidden. But then you will face the break point again. So you cannot set a break point within your OnPaint() function.
The problem is the break point: ... So you cannot set a break point within your OnPaint() function.
I'm not entirely sure that that is the case. internal WM_PAINT message is sent only once by Windows. OnPaint() will not be called again until the window is invalidated or RedrawWindow() is called (with RDW_INTERNALPAINT flag set).
In the code the OP posted, the DC doesn't look like it is set up correctly
1 2 3 4 5 6 7
//...
CDC dc;
CBrush brush;
COLORREF color=RGB(155,155,155);
brush.CreateSolidBrush(color);
dc.FillRect(&rect,&brush);// MFC will beak here as the DC is not setup correctly
//...
I agree: OnPaint() cannot be debugged by means of a breakpoint. I also agree that WM_PAINT is only sent if no other WM_PAINT is in queue. But then again, OnPaint() is called after retrieving WM_PAINt via GetMessage(), right? That I think is enough to produce another WM_PAINT. It would be interesting to know if there is a point where a breakpoint could be set without producing another WM_PAINT message. I haven't found one, though. Maybe before the call to BeginPaint()?
It is strange for sure. When the breakpoint activates, is your window obscured by Visual Studio? Because this only happens if the breakpoint causes the Visual Studio (or whatever IDE, my apologies for forgetting there are others) window to cover part of the test window.
It has been a while since I last used MFC but I have a feeling that Just because there is WM_PAINT it does not mean that OnPaint will be called. There is a habit of cashing the view and painting that back if nothing has changed (window is invalidated).
Anyway The OPs code was tested and MFC breaks at the point indicated.
I did observe the same as webJose. But Grey Wolf you're right that CDC dc; doesn't look right and I'd say that it has to be CPaintDC dc(this); // device context for painting But I'd expect that the former simply does nothing.
I haven't used MFC since a couple of years. I'm somewhat surprised that there're ppl using it dispite of by far better alternatives
I guest the CDC::FillRect() will refresh the control or it produce the message ON_PAINT.so the OnPaint() function
called again. and my program is running on VS2005.