Domanda

I am using WS_EX_COMPOSITED style in my application but its running the CPU to 100%, is there way to stop my application drawing for a while and to resume only when i need ? Some people are suggesting to use Sleep's but where exactly in WndProc do i put sleeps ?

Thanks in advance.

È stato utile?

Soluzione

Don't use Sleep. It is the solution to almost no problems.

It's true that WS_EX_COMPOSITED can hog CPU but mostly on XP in my experience. There is a much less significant performance hit on Vista and up. However, if your app is idle then it won't be repainting. If your CPU is 100% and the app is idle then you are doing something wrong in your WM_PAINT handling. What you describe sounds like an endless loop of paint cycles. If you do things right, that won't happen, even if you use WS_EX_COMPOSITED.

As regards the right way to do double buffering, BeginBufferedPaint is the modern way to do this, on Vista and up.

Altri suggerimenti

If you sleep the application's thread it will make the application UI unresponsive. It sounds to me like you need to implement your drawing code in its own thread. You can then sleep that thread without affecting the rest of your application, although I recommend using events and WaitForSingleObject/WaitForMultipleObjects calls instead of sleep.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top