For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > April 2006 > Calling Screensaver









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Calling Screensaver
Ole Weigelt

2006-04-29, 6:56 pm

Hi everybody,

can anybody tell me how I can activate the screensaver from VB?

Thanks for your help

Ole


Tom Esh

2006-04-29, 6:56 pm

On Sat, 29 Apr 2006 22:48:07 +0200, "Ole Weigelt"
<o.weigelt@officeworks.de> wrote:

>can anybody tell me how I can activate the screensaver from VB?


Assuming the screensaver is enabled:

'API declarations (bas module)...
Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Const WM_SYSCOMMAND = &H112&
Public Const SC_SCREENSAVE = &HF140&
Public Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long


'usage (anywhere)...
Dim hwnd As Long

hwnd = GetForegroundWindow()
If hwnd = 0& Then
hwnd = GetDesktopWindow()
End If
If hwnd <> 0& Then
PostMessage hwnd, WM_SYSCOMMAND, SC_SCREENSAVE, ByVal 0&
End If


Note if you're running the code in a Form module, you can dispense
with getting the Foreground or Desktop window and just post it to
Me.hwnd.


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

2006-04-30, 3:56 am

Wow, works by copy & paste.
Perfekt!

Thanks again

Ole

"Tom Esh" <tjeshGibberish@suscom.net> schrieb im Newsbeitrag
news:8bm752lmhihal0vpf73bqh7g6llhj54ha9@
4ax.com...
> On Sat, 29 Apr 2006 22:48:07 +0200, "Ole Weigelt"
> <o.weigelt@officeworks.de> wrote:
>
>
> Assuming the screensaver is enabled:
>
> 'API declarations (bas module)...
> Public Declare Function GetDesktopWindow Lib "user32" () As Long
> Public Const WM_SYSCOMMAND = &H112&
> Public Const SC_SCREENSAVE = &HF140&
> Public Declare Function PostMessage Lib "user32" _
> Alias "PostMessageA" _
> (ByVal hwnd As Long, ByVal wMsg As Long, _
> ByVal wParam As Long, lParam As Any) As Long
> Public Declare Function GetForegroundWindow Lib "user32" () As Long
>
>
> 'usage (anywhere)...
> Dim hwnd As Long
>
> hwnd = GetForegroundWindow()
> If hwnd = 0& Then
> hwnd = GetDesktopWindow()
> End If
> If hwnd <> 0& Then
> PostMessage hwnd, WM_SYSCOMMAND, SC_SCREENSAVE, ByVal 0&
> End If
>
>
> Note if you're running the code in a Form module, you can dispense
> with getting the Foreground or Desktop window and just post it to
> Me.hwnd.
>
>
> -Tom
> MVP - Visual Basic
> (please post replies to the newsgroup)



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com