I have made a simple test application that I use to paint objects while I study and try to give them physics such as gravity, velocity, wind, momentum, etc.

I have the app setup like this:

WM_PAINT
PaintFunction();
break;


DWORD CalculationsThread()
{
while( 1 )
{
     //-_-_Calculations here
    SendMessage( WindowsHandle, WM_PAINT, 0, 0 ):
   Sleep( DelayTime );// usually 10 miliseconds
}
return 0;
}

This animation is what happens: http://img220.imageshack.us/img220/3913/42771348.gif

Everything paints fine, but after little time it all goes into default colors and never returns.

I dont want to jump into Opengl or directx yet since I want to focus on being able to give objects life before how they are drawn.

Is there a way to fix this?

Regards,

Gen

Ancient Dragon commented: Cool :) +26

Recommended Answers

All 4 Replies

>>Is there a way to fix this?

Probably. My guess is that the program is not using the right brush color for painting. There are lots of ways to do that but the simplest might be to make the brush a global object so that it doesn't get destroyed between paint function calls.

Ah thanks the problem was the brush and the pens, I used

SelectObject( hdc, CreateSolidBrush( etc... ) );

So now I create the brushes with a handle and delete them at the end of the function.

Another problem that Ive been getting is Blues screens of death, about 3-4 so this worries me.

When I check for the last error, it tells me that it is a invalid handle. Just doesn't tell me to what.

I think i might have to dive into opengl or directx to avoid all these drawing problems so that I can focus more on the math section of what I wanted to make.

Ah thanks the problem was the brush and the pens, I used

SelectObject( hdc, CreateSolidBrush( etc... ) );

Seems like you have been leaking GDI objects. You might be interested in reading Pushing the Limits of Windows: USER and GDI Objects – Part 1.

>> Another problem that Ive been getting is Blues screens of death, about 3-4 so this worries me.
That's likely due to a malfunctioning driver/hardware, user mode programs don't (directly) cause BSODs.

>> When I check for the last error, it tells me that it is a invalid handle. Just doesn't tell me to what.
What is the failing function in question here?

It has been fixed by creating and deleting handles to the objects instead of skipping the step and going straight to selecting a initialization.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.