Tech Support > Microsoft Windows > Development Resources > opengl program wont yield to screensaver
opengl program wont yield to screensaver
Posted by rodburch on February 21st, 2006


when my program, which uses opengl, is full screen, i receive the
WM_SYSCOMMAND with wParam = SC_SCREENSAVE message, so i can disable
opengl to let my screensaver begin.
{if i do not do this, the screensaver does not start correctly.)

but, when my opengl program is running in a smaller window, and does
NOT have the focus, i don't detect any particular message when the
screensaver tries to start.

is this normal? that the SC_SCREENSAVE message is only sent to the
window that has the focus? or can i do something to ensure that my
non-focussed window receives that message.

thanks,

rod

Posted by Grzegorz Wróbel on February 22nd, 2006


rodburch wrote:

Only active window receives WM_SYSCOMMAND with the wParam parameter set to the SC_SCREENSAVE value. if an active window pass this message to DefWindowProc, the screensaver won't start.

Your problem is not your opengl app, but your screensaver who should be able to run, even if your opengl window is open.
--
677265676F727940346E6575726F6E732E636F6D

Posted by Lucian Wischik on February 22nd, 2006


"rodburch" <rb76543@yahoo.com> wrote:
This is normal. You could ensure that your window receives the message
by subclassing every window in the system, but YUCK.

If you really want to prevent the saver from executing even while
you're in the background, then, maybe this will help? (I don't know;
never tried it; it just looks useful...)

(presumably the "screensaver's timer" they mention is the idle-timer
which, when it reaches a certain amount, will send a
WM_SYSCOMMAND/SC_SCREENSAVE to the topmost window.)

--
Lucian

Posted by Grzegorz Wróbel on February 22nd, 2006


Grzegorz Wróbel wrote:
If an active window doesn't pass this message to DefWindowProc, the screensaver won't start.

--
677265676F727940346E6575726F6E732E636F6D

Posted by Kellie Fitton on February 22nd, 2006


Hi,

Some programmers use system wide hooks (WH_GETMESSAGE hook) and
watch for windows message WM_SYSCOMMAND with SC_SCREENSAVE,
to monitor/control the screen saver program, personally however, I
think using
a hook is always a bad idea though, but it's an option.

Kellie.

Posted by rodburch on February 22nd, 2006


thanks for all the replies. just to be clear, lucian, my problem is
that when my window is not active, it completely blocks opengl
screensavers, and causes non-opengl screensavers to hang for several
seconds between frames. i have confirmed this by disabling opengl
whenever my window receives a WM_KILLFOCUS message; both types of
screensavers run normally then (but then my program has lots of other
problems, so that doesn't look like a practical approach).

it appears that i have some other bug in my program, if the only
apparent fix is to do something that is either 'YUCK' or 'a bad idea'.
i'll keep digging.

thanks to all of you,

rod

Posted by Lucian Wischik on February 22nd, 2006


"rodburch" <rb76543@yahoo.com> wrote:
My instinct is to follow this route. OpenGL programs shouldn't
normally do this.

Note: screensavers switch down to IDLE_PRIORITY_CLASS once they've
started. If your program is taking too much CPU-time then they won't
get a look-in.

Maybe your app is running in a tight loop rather than Sleep()ing or
waiting for WM_TIMER messages. Or maybe your graphics accelerator
driver does busy-waits when you flip frames. You could try switching
to a non-accelerated PIXELFORMATDESCRIPTOR to see if the behavior
continues. (this might isolate the problem into either driver or your
app being too demanding).

You might also consider lowering your priority class upon
WM_KILLFOCUS.

--
Lucian

Posted by rodburch on February 22nd, 2006


Lucian said: "Maybe your app is running in a tight loop rather than
Sleep()ing or waiting for WM_TIMER messages."

that fixed it: adding a Sleep(0) to my main loop cured the problem
without a much of a performance hit in my program.

thanks for this information, and thanks as well for your website:

http://www.wischik.com/scr/

i was actually trying to create my first screensaver, using your site,
when i realized that my animation program wasn't behaving.

rod


Similar Posts