PDA

View Full Version : Burning c++ newbie question.


Vexed
01-28-2005, 10:33 AM
Hello,
I hope someone can answer this, since I've been wondering for a long time. I tried searching on google, but I'm not sure what key words to use. I didn't get any results (none that came close to having to do with my question anyway).

Anyway,
Why is it that a simple windows application, that only paints a window and nothing more, takes up about 50% of the CPU?

Also, every program from my directX books takes up about 50%, no matter what.

Yet, when I create an application in java (not an applet) it takes up less than 10%.

NutWrench
01-28-2005, 10:50 AM
I haven't coded in C for a long time, but you probably need to use a different routine for polling the keyboard. Something that tells Windows that this program is not time-critical and that it is willing to share CPU time with the rest of the system.

DudeMiester
01-29-2005, 10:17 AM
Use WaitForMessage in your message pump. That way the program will sit idle taking 0 CPU until it recieves a message.

Destroyer
01-29-2005, 11:55 PM
thats a good question

CronoMan
01-31-2005, 06:38 AM
I think you might have a strange problem.

when you say DirectX, are you thinking about DirectDraw, or Direct3D?


switch(msg)
{
case WM_PAINT:
(paint code here, if any)
break;
}


or you can just use the CallDefaultWindowProc or whatever it is called, and it should draw itself correctly automatically.

This is the normal way to do it, using the windows message queue, I can't see how this should get your CPU up to 50% load...

warlordQ
03-23-2005, 11:39 PM
Do you have any USB devices plugged in??? Yep the problem lies there http://forums.3drealms.com/ubbthreads/images/graemlins/smile.gif just unplug those USB devices.. then try it again...

Vexed
03-29-2005, 08:04 PM
no usb deviced plugged in.
See attachment for a piece of code that takes up 50% of the cpu when run.

DudeMiester
04-01-2005, 11:46 PM
That makes sense, the computer never stops working on that one. The only reason it isn't 100% usage is because sometimes it's waiting for the GPU to finish rendering. If you want less then that, then you have to cap the FPS. Like add a Sleep(30) after you draw the frame.

CronoMan
04-26-2005, 04:31 AM
I just found out why I like this forum.

People say "newbie" instead of n00b.

Too bad there are so few people here on the programming section http://forums.3drealms.com/ubbthreads/images/graemlins/frown.gif