PDA

View Full Version : Losing Windows DC ?



AndrewJJ
10-31-2002, 12:05 AM
Hi,
I posted this a while ago ... never got a solution to it ...

After running my OpenGL application, I sometimes find that following a timeout on the power management monitor the screen is either corrupted or more often just a plain cyan color. I've found that other OpenGL apps do the same but not all of them. It looks as though Windows is being assigned an incorrect DC after the monitor is restored after the power down ... obviously my fault !

Anyway, here's the code that I'm using to close the OpenGL application ... as I said, it all works fine ... unless the power management kicks in !

(Delphi)

procedure FinalizeOpenGL;
begin
wglMakeCurrent(fGLDC, 0);
wglDeleteContext(fGLContext);
ReleaseDC(fWindow, fGLDC);
UnloadOpenGLLibrary;
if (fPalette <> 0) then
DeleteObject(fPalette);
end; {FinalizeOpenGL}

I really would be grateful if anyone could shed some light on what I'm doing ... or not doing !

Regards

Andrew

V-man
10-31-2002, 04:32 PM
If i were you I would search the msdn (http://msdn.microsoft.com)

search for "power management" + "screen coruption"

I think that every window gets a message (in windows anyway) when power managment is about to kick in, and you just return a value to prevent that from happening.

V-man

jwatte
10-31-2002, 05:21 PM
Power management does not shut down your application, so I don't see why you're posting that code.

Look for PBT_APMSUSPEND and friends on MSDN to figure out how to handle power status changes, if you want to nicely suspend your app.

AndrewJJ
10-31-2002, 09:09 PM
Sorry for not making the problem 100% clear. Power management kicking is fine ... no problems at all ... that is until I've run my OpenGL application and then terminated it. Then everything's OK until power management kicks in and upon restoring I then get this cyan screen.