Click to See Complete Forum and Search --> : Screensavers
chrisjk
Nov 21st, 1999, 12:21 AM
Hi all,
The code posted here before for starting the screensaver doesn't work!
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_SYSCOMMAND As Long = &H112&
Public Const SC_SCREENSAVE As Long = &HF140&
Function gf_StartScreenSaver() As Boolean
Dim hWnd&
On Error Resume Next
hWnd& = GetDesktopWindow()
Call SendMessage(hWnd&, WM_SYSCOMMAND, SC_SCREENSAVE, 0&)
gf_StartScreenSaver = (Err.Number = 0)
End Function
It can be found at http://www.vb-world.net/tips/tip146.html. I even followed the suggested correction by John Ryan in the feedback bit, with no effect.
It complains that GetDeskTopWindow() is not defined as a function. I can see why, but what is GetDeskTopWindow and why is it not included in the code sample by John Percival?
I intend using it as a simple way to lock my PC when I'm not using it (with the screensaver password), if I could get it to work!
Any ideas...Thanks guys
- Chris
Yonatan
Nov 21st, 1999, 12:25 AM
Add this line to the very beginning:
Declare Function GetDesktopWindow Lib "user32" () As Long
------------------
Yonatan
Teenage Programmer
E-Mail: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)
AIM: RYoni69
chrisjk
Nov 21st, 1999, 12:30 AM
cheers mate! I knew it would be simple, but using declares ain't my strong point. Congratulations on the stunning response time..i only posted 2 minutes ago!
Yonatan
Nov 21st, 1999, 12:37 AM
Make the question any simpler and it would be 30 seconds (just kidding :))...
------------------
Yonatan
Teenage Programmer
E-Mail: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)
AIM: RYoni69
MiDaWe
Nov 21st, 1999, 03:16 PM
Hey,
I think that using this code for security issue is a great idea. So, I tried to use it in a VB project, but it failed.
This is the error that I get:
Compile error:
Constants, fixed-length strings, arrays, user-defined types and Declare statements not alloed as Public members of object modules
Can anyone explain what this means and how I can fix this to work. (I used the code on this page exactly).
------------------
Thanks,
MiDaWe
Did you put the code inside a form?
If so try putting Private before the Declare Function GetDesktopWindow Lib "user32" () As Long
If you don't specify private/public the default is public, and the won't work in forms.
------------------
Vincent van den Braken
EMail: azzmodan@azzmodan.demon.nl
ICQ: 15440110 (http://www.icq.com/15440110)
Homepage: http://www.azzmodan.demon.nl
MiDaWe
Nov 21st, 1999, 04:50 PM
I added Private before the Declare Function GetDesktopWindow Lib "user32" () As Long
But, I still get the same error. What should I look for next? I don't need to use a form for this project. I aim to just have the screen saver activate on startup.
------------------
Thanks,
MiDaWe
chrisjk
Nov 22nd, 1999, 02:01 AM
Hey MiDaWe,
What i did is put the following in a module (like module1)...
Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_SYSCOMMAND As Long = &H112&
Public Const SC_SCREENSAVE As Long = &HF140&
Then I made a sub in the same module called Main (so it starts automatically without any forms needed in the project) and put the following in...
Sub Main()
Dim hWnd&
On Error Resume Next
hWnd& = GetDesktopWindow()
Call SendMessage(hWnd&, WM_SYSCOMMAND, SC_SCREENSAVE, 0&)
gf_StartScreenSaver = (Err.Number = 0)
' make sure you include this otherwise your app will never end (until you switch off PC)!
End
End Sub
Then compile an EXE making sure Sub Main is your startup form thingy, and run it. Works great for me!
Cheerio - hope that helps
- Chris
In a form also replace the publics that are used by the constants:
Public Const WM_SYSCOMMAND As Long = &H112&
Public Const SC_SCREENSAVE As Long = &HF140&
Should be:
Private Const WM_SYSCOMMAND As Long = &H112&
Private Const SC_SCREENSAVE As Long = &HF140&
Or try adding the code to a module.
------------------
Vincent van den Braken
EMail: azzmodan@azzmodan.demon.nl
ICQ: 15440110 (http://www.icq.com/15440110)
Homepage: http://www.azzmodan.demon.nl
chrisjk
Nov 23rd, 1999, 01:30 AM
Anytime MiDaWe! It's great when little things like that work!
Regards,
------------------
- Chris
chris.kilhams@btinternet.com
MiDaWe
Nov 23rd, 1999, 11:48 AM
Hey chrisjk,
Thanks that's exactly what I was looking for. It works great. I compiled it and I ready to disapoint the next person to boot my computer without my permission. :) he he he.
I know that it's easy to hack around, through DOS but the person who has been using my computer without my permission doesn't know that.
------------------
Thanks,
MiDaWe
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.