Results 1 to 11 of 11

Thread: Screensavers

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    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

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    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
    AIM: RYoni69

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    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!

  4. #4
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    Make the question any simpler and it would be 30 seconds (just kidding )...

    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: RZvika@netvision.net.il
    ICQ: 19552879
    AIM: RYoni69

  5. #5
    Junior Member
    Join Date
    Nov 1999
    Posts
    25

    Post

    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

  6. #6
    Guest

    Post

    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
    Homepage: http://www.azzmodan.demon.nl




  7. #7
    Junior Member
    Join Date
    Nov 1999
    Posts
    25

    Post

    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

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    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

  9. #9
    Guest

    Post

    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
    Homepage: http://www.azzmodan.demon.nl




  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    Anytime MiDaWe! It's great when little things like that work!

    Regards,

    ------------------
    - Chris
    chris.kilhams@btinternet.com

  11. #11
    Junior Member
    Join Date
    Nov 1999
    Posts
    25

    Post

    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
  •  



Click Here to Expand Forum to Full Width