Home All Groups Group Topic Archive Search About

How to Use a Screen Saver app within My Application?

Author
24 May 2006 10:26 AM
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

Author
24 May 2006 4:00 PM
Tom Esh
On Wed, 24 May 2006 06:26:52 -0400, "TCook" <getmyemai***@yahoo.com>
wrote:

>
>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)
Author
25 May 2006 1:00 AM
TCook
Once launched, how can the screensaver be terminated programmatically?



Show quoteHide quote
"Tom Esh" <tjeshGibber***@suscom.net> wrote in message
news:520972t9iq47aqstalm891m2dhfcdn97ho@4ax.com...
> On Wed, 24 May 2006 06:26:52 -0400, "TCook" <getmyemai***@yahoo.com>
> wrote:
>
>>
>>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)
Author
25 May 2006 2:39 AM
+Vice
Interesting, can we do the same for an application?  Kind of make like a
container for our executed application?

Show quoteHide quote
"Tom Esh" <tjeshGibber***@suscom.net> wrote in message
news:520972t9iq47aqstalm891m2dhfcdn97ho@4ax.com...
> On Wed, 24 May 2006 06:26:52 -0400, "TCook" <getmyemai***@yahoo.com>
> wrote:
>
>>
>>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)
Author
25 May 2006 4:48 PM
Karl E. Peterson
+Vice wrote:
>>> 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
>
> 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.")
--
Working without a .NET?
http://classicvb.org/
Author
24 May 2006 4:06 PM
Karl E. Peterson
TCook wrote:
> 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)

--
Working without a .NET?
http://classicvb.org/
Author
24 May 2006 6:49 PM
TCook
Thanks a bunch guys!


Show quoteHide quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:OQJafw0fGHA.4172@TK2MSFTNGP04.phx.gbl...
> TCook wrote:
>> 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)
>
> --
> Working without a .NET?
> http://classicvb.org/
>
>
Author
25 May 2006 1:00 AM
TCook
Once launched, how can the screensaver be terminated programmatically?




Show quoteHide quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:OQJafw0fGHA.4172@TK2MSFTNGP04.phx.gbl...
> TCook wrote:
>> 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)
>
> --
> Working without a .NET?
> http://classicvb.org/
>
>
Author
25 May 2006 4:50 PM
Karl E. Peterson
TCook wrote:
> 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.
--
Working without a .NET?
http://classicvb.org/
Author
25 May 2006 6:04 PM
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



Show quoteHide quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:e0W85uBgGHA.4172@TK2MSFTNGP04.phx.gbl...
> TCook wrote:
>> 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.
> --
> Working without a .NET?
> http://classicvb.org/
>
>
Author
25 May 2006 7:23 PM
Karl E. Peterson
TCook wrote:
>>> 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.
>
> 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
--
Working without a .NET?
http://classicvb.org/
Author
26 May 2006 12:24 AM
TCook
Hey Karl,

Go it!  Thanks for the help ;-)

Regards,

TC



Show quoteHide quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:%23lMU7CDgGHA.4276@TK2MSFTNGP03.phx.gbl...
> TCook wrote:
>>>> 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.
>>
>> 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
> --
> Working without a .NET?
> http://classicvb.org/
>
>