CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: redraw

  1. #1
    Join Date
    May 2011
    Posts
    23

    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

  2. #2
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    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

  3. #3
    Join Date
    May 2011
    Posts
    23

    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.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: redraw

    Quote Originally Posted by lch2 View Post
    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()?

  5. #5
    Join Date
    May 2011
    Posts
    23

    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 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
  •  





Click Here to Expand Forum to Full Width

Featured