CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2001
    Location
    Steubenville Ohio
    Posts
    76

    getting animation using doc redraw

    This is similar to a post that I put on the beginner thread but I haven't yet been able to get a solution.

    I have a simple SDI program and I am trying to handle a message from the menu in two different ways. One way, I handle the message in CFlashView and the other way, I handle the message in CFlashDoc. What I am trying to do is make the client area of a window flash through a bunch of colors - the real point is that I want to refresh a view that uses document information from the document. I think that there are three important parts of code from the two different methods:
    1) CFlashView::OnFileRun()
    2) CFlashDoc::OnFileRun()
    3) CFlashView::OnDraw <--- not really that important

    When I do this by putting the command handler in the CFlashView, it flashes the way that I want it to. When I put the command handler in CFlashDoc, it seems to run through the entire loop and then at the end, it refreshes the screen with the same picture that you get from the view but it doesn't show the intermediate colors and thus "flash".

    What do I have to modify to make the screen flash if I put the command handler in the documnet?

    void CFlashView::OnFileRun()
    {
    CFlashDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);

    CClientDC* pDC = new CClientDC(this);
    for(int x=0;x<1000;x++)
    {
    pDoc->m_colorPoint++;
    OnDraw(pDC);
    }
    }
    =====================
    void CFlashDoc::OnFileRun()
    {
    for(int x=0;x<100000;x++)
    {
    m_colorPoint++;
    UpdateAllViews(NULL);
    }

    }
    =====================
    void CFlashView::OnDraw(CDC* pDC)
    {
    CFlashDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);

    CRect aRect;
    pDC->GetWindow()->GetClientRect(aRect);

    pDC->FillSolidRect(aRect,RGB((pDoc->m_colorPoint)%255,
    (pDoc->m_colorPoint*2)%255,
    (pDoc->m_colorPoint*3)%255
    )
    );
    }



  2. #2
    igbrus is offline Elite Member Power Poster
    Join Date
    Aug 2000
    Location
    Los Angeles
    Posts
    4,658

    Re: getting animation using doc redraw


    void CFlashDoc::OnFileRun()
    {
    for(int x=0;x<100000;x++)
    {
    m_colorPoint++;
    UpdateAllViews(NULL);
    MSG msg;
    while( ::PeekMessage(&msg,NULL, 0, 0, PM_REMOVE)
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    }

    }




    Rating isn't important...But gurus respect it and keep high

  3. #3
    Join Date
    Jul 2001
    Location
    Steubenville Ohio
    Posts
    76

    Re: getting animation using doc redraw

    GREAT!!! That solves the problem though I still haven't figured out exactly what it's doing. A thing that I've noticed is that there is alot more screen flicker when I do this. I think that it redraws the entire screen instead of just the modified areas. Is there any way to just do the modified regions? If not, I can just put this back in each view or the mainframe where I can do an OnDraw.

    Thank you very much


  4. #4
    Join Date
    Mar 2001
    Location
    Singapore
    Posts
    57

    Re: getting animation using doc redraw

    hi there, is it possible to let me have a look at that program you are writing? A sample
    will do too!
    thanks


  5. #5
    igbrus is offline Elite Member Power Poster
    Join Date
    Aug 2000
    Location
    Los Angeles
    Posts
    4,658

    Re: getting animation using doc redraw

    Typically you should not perform any drawing directly from OnUpdate. Instead, determine the rectangle describing, in device coordinates, the area that requires updating; pass this rectangle to CWnd::InvalidateRect. You could pass the rectangle via second parameter of UpdateAllViews:
    RECT rect;
    UpdateAllViews(NULL, (LPARAM)&Rect);

    Rating isn't important...But gurus respect it and keep high

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