thanks for your reply. Got a new Question:
When I override the CWnd::PreSubClass for my sliders. Do I have a correct DC at that point? Or is ist created afterwards? Or did you mean I should override PreSubClass and ALSO create the memDC in the OnPaint Handler? What for do I need the PreSubClass-Method then?
I would ignore the PreSubClass completely (for this reason at least - for all I know you have other work to do).
And in your OnPaint handler, I would use Keith Rule's CMemDC class - creating the bitmaps will be pretty speedy, and it keeps your code clean. It will even blt the image to the screen with it goes out of scope. Flicker Free Drawing In MFC[^]
I cannot recommend this article highly enough.
I used to cache my own memory DCs, but it wasnt worth the hassle, and the speed hit of recreating them is essentially 0.
I want to develop a Multithread SDI application where a ball(drawing an ellipse) is created for every thread.
The user is given the option of selecting N no of balls ( say N < 5).
The trajectory/movement of the ball is random of each other. These bounce-off once they hit any one of the sides of the client rect.
Assume that I have the points through which each ball has to traverse (which is different for each ball), how do i start of with this application?
I never made an application like this, but do you think it's necessairy to create
for each ball a thread?
What I had in mind was for each thread, within that thread, I Create a ball object and in a while loop, get the necessary paramerers (trajectory) of the ball by making call functions. Periodically I keep updating the UI with the info.
As I read it, the programmer (I'm guessing it's not you) has just put an assert in there. (s)he could just be checking that things he expects to be true are actually true. Maybe unless m_Mode is OPEN, then m_MessageProps would be empty, and he wants to catch the reasons why the find routine would fail.
It's always possible this is a line of fossil code, and m_Mode is no longer necessary. But unless you understand the code, I'd leave it in also.
You could pass it as your thread argument. If you look at the documentation of the create thread function that you use, you'll see that it can accept an argument, that will be passed to your thread function through the LPVOID Param.
So, you can simply do that in your thread function:
There are things to be careful of though. You have to ensure that the CMyClass object will last longer than the thread routine. Or at least longer than the thread routine will use it.
And in your routine, you are using CASyncSocket. This class uses asynchronous socket behaviour, and responds to messages from winsock, rather than blocking on them. It does *not* mean that it is thread safe. It *might* be if you only send from one thread, and read on another, but don't assume that. This is why I use pretty raw win32 code in my threads, as MFC is explicitly not thread friendly. I'll use CWnd derived classes for it, but only to get access to the m_hWnd member to post messages back to them.
Last Visit: 31-Dec-99 18:00 Last Update: 22-Jun-21 8:34