Click to See Complete Forum and Search --> : Drawing in SDI without OnDraw
deepak_99218
May 26th, 2008, 02:05 AM
I am a beginner.
I am creating a SDI : CFormView.
How can i Draw on the form without using the OnDraw method ?
I use this for animation based on user input.
Can i run it as a seperate thread, so that it can run in a loop, how ?
CBasicNet
May 27th, 2008, 04:59 AM
Yes you can draw on it without using OnDraw. But you must cache your drawing somewhere and draw it in OnDraw, else the next OnDraw/EraseBnkgnd will wipe out your drawing when it is OnDraw's turn to draw. As a rule of thumb, you cannot run/call UI stuff in a worker thread. Another problem is what if your thread and OnDraw draws on it at the same time?
srelu
June 6th, 2008, 01:11 AM
You don't need a thread to do that.
If the animation should occur only when the user is doing something then a good place to put the drawing code are the handlers of the keyboard and/or mouse messages.
If the animation should occur all the time, regardless wether the user is doing something or not, set up a timer (see SetTimer) and place the animation code in the timer procedure.
Don't forget what CBasicNet said about OnDraw.
Note that plain Visual C++ code can be used only on simple animation where the time isn't a critical factor. Such applications experience frequent delays and slow answer from the system.
If you want to write a game where quick response from the system is important, you need to use DirectX.
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.