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.

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top