B
Ben Taylor
Hi,
I am writing a program that uses different threads to handle various
painting operations, I wondered if somebody could possible tell me if I
create a new thread using AfxBeginThread(ThreadFunc, &threadparams, ... and
then the various options to create it suspended, and then have it resume.
What I want to know is, can the threadparams structure include a CDC * that
enables the thread to draw to the window, as long as I use a (single)
critical section inside threadparams aswell to make sure that no two threads
draw to the CDC at once??? If not how can I accomplish the same end? If they
can't access the same dc is there any way of making the starting function
for the thread a class member function of the dialog window class, that way
the thread function could create its own DC using the CClientDC dc(this)
statement - I thought threads had to start on global functions but I'm not
so sure if this might be standard practice or not. I understand how new
threads being kicked off works and how critical sections work but I don't
want to go down the line of designing my program on the assumption that
different threads can modify the same CDC * or whether this will assert or
throw an exception when I have carefully designed what I think to be a good
algorithm, or is this the way to go?
Thus, enabling me to produce multiple animations on the window. The thread
that is doing the animation is going to be doing a loop with, say, a
Sleep(20) in it and then some code to erase the moving object from its old
position and redraw it in its new position. BTW the CDC would almost
definitely be a CClientDC rather than a CPaintDC, because CPaintDCs have a
special action in their destructor don't they that needs to be done?
I am writing a program that uses different threads to handle various
painting operations, I wondered if somebody could possible tell me if I
create a new thread using AfxBeginThread(ThreadFunc, &threadparams, ... and
then the various options to create it suspended, and then have it resume.
What I want to know is, can the threadparams structure include a CDC * that
enables the thread to draw to the window, as long as I use a (single)
critical section inside threadparams aswell to make sure that no two threads
draw to the CDC at once??? If not how can I accomplish the same end? If they
can't access the same dc is there any way of making the starting function
for the thread a class member function of the dialog window class, that way
the thread function could create its own DC using the CClientDC dc(this)
statement - I thought threads had to start on global functions but I'm not
so sure if this might be standard practice or not. I understand how new
threads being kicked off works and how critical sections work but I don't
want to go down the line of designing my program on the assumption that
different threads can modify the same CDC * or whether this will assert or
throw an exception when I have carefully designed what I think to be a good
algorithm, or is this the way to go?
Thus, enabling me to produce multiple animations on the window. The thread
that is doing the animation is going to be doing a loop with, say, a
Sleep(20) in it and then some code to erase the moving object from its old
position and redraw it in its new position. BTW the CDC would almost
definitely be a CClientDC rather than a CPaintDC, because CPaintDCs have a
special action in their destructor don't they that needs to be done?