Bitmap animation with Thread

I am a beginner at MFC and I am going to make a simple game with some card images.
When I click a button, the cards have to appear in the window with an apposite animation.
I had made animation in a function to the following:

1
2
3
4
5
for (int i=0; i<nStep; i++)
{
  // Draw bitmap
  Sleep(30);
}


But while the animation is playing, I can't do anything neither click button nor chat. So I have a decision to make an animation thread. However the Device Context (dc) is the biggest problem because the main thread and animation thread will control one dc together.

What can I do for solving this problem? Help me. Thank you.
So you basically want multithreading/multitasking?
Or you could make it so the function doesn't hang but instead use a timer to see how long has actually passed and if the desired amount of time has passed then do what ever.
I am sorry about the late reply.
You are right. I want to make a multithreading program.
So I am going to process window messages and bitmap animations at one time side by side.
Last edited on
If you wish to use threads http://www.cplusplus.com/reference/thread/thread/
or you could use boost threads.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// thread example
#include <iostream>       // std::cout
#include <thread>         // std::thread
 
void foo() 
{
  // do stuff...
}

void bar(int x)
{
  // do stuff...
}

int main() 
{
  std::thread first (foo);     // spawn new thread that calls foo()
  std::thread second (bar,0);  // spawn new thread that calls bar(0)

  std::cout << "main, foo and bar now execute concurrently...\n";

  // synchronize threads:
  first.join();                // pauses until first finishes
  second.join();               // pauses until second finishes

  std::cout << "foo and bar completed.\n";

  return 0;
}
main, foo and bar now execute concurrently...
foo and bar completed.
Thank you very much.
How can I make it with boost thread?
Main thread and animation thread have to use the one dc.
So collision is inevitable. How can I avoid it?
Topic archived. No new replies allowed.