Image of Navigational Panel mapped to Contents / Home / Search Developing a Screensaver
Tech Support Question

Image of Line Break

Q. I developed a screensaver in VB and I am one step away from completing it, but I can't seem to stop it with a mousemove or key press. Can you help? I would really appreciate it.

From: Joe
Email: brunoj@philly.infi.net

A. Joe, this really depends on what sort of screensaver you have written and how it works. The general case for a screensaver written in VB would have a large black borderless form that covers the screen so that you can then draw stuff on it and make noises and whatever. In that case all you need to do then is pick up the MouseMove, MouseClick and KeyDown events of that form and end the screensaver then. If you have controls on the form you will probably want to check the mouse events of those. If you set the keypreview property of the form to true you should then be able just check the KeyDown event for the form which will fire before the keydown event of any child controls.

If you are using some other method to screen save then you probably need to use the PeekMessage API continually to check for any appropriate Windows messages being sent to any window. It would be called something like this:

  DIm msgX as MSG
  if PeekMessage(msgX, 0&, WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE) then
    ' End App
    Unload Me ' ?
  endif
  if PeekMessage(msgX, 0&, WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE) then
    ' End App
    Unload Me ' ?
  endif

Of course the declarations and explanations of the constants I've mentioned above are in the API help files that ship with VB. Essentially this code is checking for any Key or Mouse message, which it will not remove from the message queue, and if it finds one it ends the app. It passes 0& as the hWnd to check for so that PeekMessage will return messages for any window.

I hope this gives you some ideas at least. Good luck with your screensaver.


Image of Arrow to Previous Article Image of Arrow to Next Article

[TECH SUPPORT TOC]
Image of Line Break
[HOME] [TABLE OF CONTENTS] [SEARCH]