December 13th, 2011, 03:02 AM
#1
redraw
To understand the mfc dialog, onpaint better, after reading some online notes, made a little project. This draws a Horz. axis with a red color curve above it. What I can not figure how to do, is to redraw the whole thing multiple times with each time the whole plot moves. Like erase/redraw thing. don't know how to erase and redraw.
Code:
void MyDraw::OnPaint()
{
CPaintDC dc(this);
DrawC(dc);
}
void MyDraw::DrawC(CDC& dc)
{
CRect rect;
GetClientRect(rect);
HDC hdc = dc.GetSafeHdc();
CPen aPen, dkpen, redPen;
aPen.CreatePen(PS_SOLID, 2, RGB(255, 225, 225));
dkpen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
redPen.CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
CPen* pOldPen = dc.SelectObject(&aPen);
CPen* gOldPen = dc.SelectObject(&dkpen);
dc.MoveTo(10,250);
dc.LineTo(220,250);
dc.MoveTo(220,250);
dc.LineTo(215,255);
dc.MoveTo(220,250);
dc.LineTo(215,245);
gOldPen = dc.SelectObject(&redPen);
dc.MoveTo(10, 250);
dc.LineTo(100, 220);
dc.LineTo(150, 200);
dc.LineTo(190, 160);
dc.LineTo(195, 130);
}
Last edited by Marc G; December 19th, 2011 at 03:38 PM .
Reason: Added code tags
December 13th, 2011, 03:26 AM
#2
Re: redraw
Hi,
What is MyDraw ?
Especially: What is inherited from?
Please use code tags (as described in the "Before you post" section)!
To "erase" something drawn generally:
In MS-Windows all drawings have to be done in responses to WM_PAINT messages.
To change a drawing you've to force Windows to redraw the control/window by calling Invalidate or InvalidateRect.
Regards PA
December 13th, 2011, 10:13 AM
#3
Re: redraw
yes, this is it:
Code:
class MyDraw : public CStatic
{
// Construction
public:
MyDraw();
//removed items....
void DrawC(CDC& dc);
};
I tried to use Invalidate but not effect.
December 13th, 2011, 10:20 AM
#4
Re: redraw
Originally Posted by
lch2
yes, this is it:
Code:
class MyDraw : public CStatic
{
// Construction
public:
MyDraw();
//removed items....
void DrawC(CDC& dc);
};
I tried to use Invalidate but not effect.
Add UpdateWindow() after it.
Invalidate will generate a WM_PAINT message. UpdateWindow will force it to be processed. Where did you call Invalidate()?
December 14th, 2011, 04:47 PM
#5
Re: redraw
how to add zoom to this dialog?. so that with mouse click one can zoom into the paint area. make res folder, copy .rc2 .ico files to it.
Attached Files
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