CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2015
    Posts
    8

    Performance issue when drawing on MFC

    Hello all & Thanks for reading this,

    -I would have a question on you:
    -I have created a small application on MFC/C++ that draw different geometric shapes on screen using the mouse (like Paint). These shapes can be moved and rotated,
    so, I had to keep all these created shapes in a vector and draw all of them in OnDraw().
    -My problem is, when I create many shapes (more than 50-60) and I try to move/rotate one of the shapes, these movements/rotations become very-very slow.
    -Could you give me some tips in order to make my application faster when moving/rotating those shapes?


    Code:
    OnDraw(CDC* pDC)
    {
    
        for (int i = 0; i < numberObjects; i++)
    	objects[i]->DrawShape(pDC);
    }

    Many thanks!

  2. #2
    Join Date
    Aug 2006
    Posts
    231

    Re: Performance issue when drawing on MFC

    Do you use MFC classes like CPen and CBrush, or what technique do you use for drawing? Can you share any more code?

    For example, it's bad for performance if every object creates and destroys a local CPen on every call to DrawShape.

  3. #3
    Join Date
    Feb 2015
    Posts
    8

    Re: Performance issue when drawing on MFC

    Hi @TubularX,

    Every "DrawShape" has a body like this: http://forums.codeguru.com/showthrea...99#post2209599 (this is also my thread).
    I can't remove parts of my code because I already tried to not complicate my code too much. I will try to redraw only those shapes that are moving/rotating using InvalidateRect and UpdateData, this way, all those shapes that are not affected will not be drawn again, and maybe this way all drawing process will be faster. I hope...

    Thanks!

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Performance issue when drawing on MFC

    Quote Originally Posted by Isaak View Post
    ...
    I can't remove parts of my code because I already tried to not complicate my code too much. I will try to redraw only those shapes that are moving/rotating using InvalidateRect and UpdateData, this way,
    But why UpdateData?
    Or you meant UpdateWindow?
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2017
    Posts
    3

    Wpt

    To analyze the problem:

    I would suggest you to use Windows Performance Tool Kit. You will able to do memory & processing analysis with it. Is it high memory usage or/and particular function consuming cpu cycles?


    Lynda course Windows Performance Tool Kit & Memory Leak will able to give you quick over view on how to use this tool. Check with your public library it might be free to access to this site.

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