|
-
Nov 21st, 1999, 01:21 AM
#1
Thread Starter
PowerPoster
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
-
Nov 21st, 1999, 01:25 AM
#2
Guru
Add this line to the very beginning:
Declare Function GetDesktopWindow Lib "user32" () As Long
------------------
Yonatan
Teenage Programmer
E-Mail: [email protected]
ICQ: 19552879
AIM: RYoni69
-
Nov 21st, 1999, 01:30 AM
#3
Thread Starter
PowerPoster
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!
-
Nov 21st, 1999, 01:37 AM
#4
-
Nov 21st, 1999, 04:16 PM
#5
Junior Member
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
-
Nov 21st, 1999, 05:34 PM
#6
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: [email protected]
ICQ: 15440110
Homepage: http://www.azzmodan.demon.nl
-
Nov 21st, 1999, 05:50 PM
#7
Junior Member
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
-
Nov 22nd, 1999, 03:01 AM
#8
Thread Starter
PowerPoster
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
-
Nov 22nd, 1999, 09:12 PM
#9
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: [email protected]
ICQ: 15440110
Homepage: http://www.azzmodan.demon.nl
-
Nov 23rd, 1999, 02:30 AM
#10
Thread Starter
PowerPoster
Anytime MiDaWe! It's great when little things like that work!
Regards,
------------------
- Chris
[email protected]
-
Nov 23rd, 1999, 12:48 PM
#11
Junior Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|