PDA

View Full Version : 100% CPU Usage



Akash
11-25-2001, 08:29 AM
Hi

I am making a litle paint program, rendering the scene using opengl, i only call the funtion to draw when i receive WM_PAINT thinking that it wont use the cpu at 100% but it still does.

Is there any way i can only render when i need too so my cpu dosent get used at 100%

case WM_ACTIVATE:
if ( ! HIWORD(wParam) )
g_bActive = TRUE;
else
g_bActive = FALSE;

break;

case WM_PAINT:

if ( g_bActive )
OnPaint();
break;

i only call onpaint if the window is active, and my cpu gets used at 100% even when the window is not active...

ET3D
11-25-2001, 02:24 PM
Try to put a breakpoint in your rendering code, to see when it's called.

Moz
11-25-2001, 11:55 PM
You have this problem because WM_PAINT is sent to your window again after every drawing of the scene. To let windows know that you have updated the window, do this:

declare a global PAINTSTRUCT structure



PAINTSTRUCT PaintStruct;


then in the wndProc function (message handler), to respond to WM_PAINT, do this:



case WM_PAINT:
{
BeginPaint(hWnd, &PaintStruct);
DrawScene();
EndPaint(hWnd, &PaintStruct);
return 0;
}


Then windows won't send the WM_PAINT message any more until it's required again.