It seems whenever I run/make a win32 program, it always uses up 100% of the cpu, at least thats what the Ctrl-Alt-Del menu in windows XP shows. Is there something wrong?
It seems whenever I run/make a win32 program, it always uses up 100% of the cpu, at least thats what the Ctrl-Alt-Del menu in windows XP shows. Is there something wrong?
>> Is there something wrong?
If it's not doing something usefull, then yes.
gg
More than likely you're using PeekMessage instead of GetMessage.
That happens because of your message loop. If you switch PeekMessage() with GetMessage(), then your CPU usage will drop back to normal levels.. although if you want stuff to happen during the time when there are no messages available, this might not be possible. Alternately, a quick-fix solution is to add a Sleep(1); line to your message loop. I believe this tells the OS basically to 'give up the rest of the CPU time slice', if I remember correctly from wherever I read it. But the real reason it works might also just be because the time spent sleeping (1ms) is hugely greater than the time spent on processing the rest of the contents of the loop - I'm no expert on such things Also try putting your message loop in a separate thread with idle priority or something.
If someone has a better solution, I'd be glad to hear it too
Last edited by Hunter2; 10-26-2004 at 05:14 PM.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Thanks alot, it reduces my crazy CPU usage. One problem though, I can't close the window from the top right
See if your function to handle messages parses WM_QUIT, WM_DESTROY and WM_CLOSE to end your aplication (calling exit or whatever).
Hunter2---Sleep(0) gives up the time slice, Sleep(1) waits a millisecond. I believe that is the way it works.
yah, from msdn:
Originally Posted by MSDN
Sleep(1) is usually used to give up the rest of the time slice as Sleep(0) only yields to threads of equal or higher priority, leaving lower priority threads dead in the water. Sleep(1) will yield to any ready thread.
While I don't know about the exact behaviour of Sleep(), I do know that Sleep(0) does not drop my CPU usage below 100%. For more info, see anonytmouse's post
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.