How to Use a Screen Saver app within My Application?

T

TCook

Hey All,

I was wondering if anyone has done or knows how to use a screen saver within
a VB app (i.e. display a running screen saver on a form or child window like
the 'Preview' functionality in the Control Panel)?

Thanks & Regards,

TC
 
T

Tom Esh

I was wondering if anyone has done or knows how to use a screen saver within
a VB app (i.e. display a running screen saver on a form or child window like
the 'Preview' functionality in the Control Panel)?

Try starting the screensaver app with ' /p nnnn' as command tail,
where nnnn is the hwnd of the "preview" window, i.e.
Shell "MySaver.scr /p " & Me.hwnd



-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
 
K

Karl E. Peterson

TCook said:
I was wondering if anyone has done or knows how to use a screen saver
within a VB app (i.e. display a running screen saver on a form or
child window like the 'Preview' functionality in the Control Panel)?

Here ya go:

Shell "sspipes.scr /p " & CStr(Picture1.hWnd)
 
V

+Vice

Interesting, can we do the same for an application? Kind of make like a
container for our executed application?
 
K

Karl E. Peterson

+Vice said:
Interesting, can we do the same for an application? Kind of make
like a container for our executed application?

Depends. It's in the screensaver spec, that if they're passed /p and an
hWnd, they are supposed to show a "preview" of their handicraft there. If
other apps are written to do similar, then sure. (Since I'm not aware of
any other application category that behaves similarly, though, I'm sure the
answer is most likely "probably not.")
 
K

Karl E. Peterson

TCook said:
Once launched, how can the screensaver be terminated programmatically?

Easiest way: Close the window to which it's attached.

Another likely way: Many screensavers will create their own window to draw
upon, and make this a child of the window passed on the command line when
invoked in preview mode. You could try enumerating the children of the
passed window, and sending WM_CLOSE.
 
T

TCook

Hey Karl,

I actually need the window to stay open so closing the form wouldn't work.
I tried sending WM_CLOSE but to the PictureBox and it closed the form and
closed my application with it ;-)

What I was hoping to do was simply end the process similar to ending the
process from the task manager but APIs I tried didn't stop it. Any ideas
there?

Thanks,

TC
 
K

Karl E. Peterson

TCook said:
I actually need the window to stay open so closing the form wouldn't
work. I tried sending WM_CLOSE but to the PictureBox and it closed
the form and closed my application with it ;-)

Don't send it to the picture box! Send it to the *child* of the picture
box. You'll need to use EnumChildWindows to find this. Or, probably just
as easily, GetWindow -- *assuming* you're not dealing with a VB-authored
screensaver. It's certainly possible that multiple windows may be parented
to your picturebox, although this is unlikely unless you're totally not
paying attention. (Not sure why I felt the need to say that. <g>) At any
rate, this works here:

Option Explicit

Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long,
ByVal wCmd As Long) As Long
Private Const GW_CHILD As Long = 5

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long
Private Const WM_CLOSE As Long = &H10

Private Sub cmdStart_Click()
Shell "sspipes.scr /p " & CStr(Picture1.hWnd)
End Sub

Private Sub cmdStop_Click()
Dim hWndPreview As Long
hWndPreview = GetWindow(Picture1.hWnd, GW_CHILD)
SendMessage hWndPreview, WM_CLOSE, 0&, ByVal 0&
End Sub
What I was hoping to do was simply end the process similar to ending
the process from the task manager but APIs I tried didn't stop it.
Any ideas there?

DON'T DO THAT! Huge Hammer; Petty Problem.

Later... Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top