July 28, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Quickstart Guide to Screensavers

  • November 19, 2002
  • By Karl Moore
  • Send Email »
  • More Articles »

As your screensaver form is unloading, you need to check whether the password is enabled and if so, prompt the user for it.

  • Add the following code behind the Unload event of your Form:
' Check password is enabledIf IsPasswordEnabled = True Then' If so, show cursorCall ShowCursor(True)' Verify passwordIf VerifyScreenSavePwd(Me.hwnd) = False Then' If incorrect, forget the UnloadCancel = TrueCall ShowCursor(False)Exit SubEnd IfEnd If' But if no password enabled' or password is correct,' it's time to clean up before leavingCall EnableCtrlAltDelete(True)Call ShowCursor(True)
  • Add the following supporting code to a module in your screensaver application:
' Password checkPublic Function VerifyScreenSavePwd Lib _    "password.cpl" (ByVal hwnd&) As Boolean' Registry API functionsPrivate Const HKEY_CURRENT_USER = &H80000001Public Const REG_DWORD As Long = 4Declare Function RegOpenKey Lib "advapi32.dll" _    Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal _    lpSubKey As String, phkResult As Long) As LongDeclare Function RegQueryValueEx Lib "advapi32.dll" _    Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal _    lpValueName As String, ByVal lpReserved As Long, _    lpType As Long, ByVal lpData As String, lpcbData _    As Long) As LongDeclare Function RegCloseKey Lib "advapi32.dll" _    (ByVal hKey As Long) As LongPublic Function IsPasswordEnabled() As Boolean    ' Checks registry to see if password is enabled    If ReadRegistry(HKEY_CURRENT_USER, "Control Panel\Desktop", _        "ScreenSaveUsePassword") = 1 Then                IsPasswordEnabled = True            End If        End FunctionPrivate Function ReadRegistry(ByVal Group _    As Long, ByVal Section As String, ByVal Key _    As String) As String    ' Reads from the registry    Dim lResult As Long, lKeyValue As Long, _    lDataTypeValue As Long, lValueLength As Long, _    sValue As String, td As Double        On Error Resume Next        lResult = RegOpenKey(Group, Section, lKeyValue)    sValue = Space$(2048)    lValueLength = Len(sValue)    lResult = RegQueryValueEx(lKeyValue, Key, 0&, _    lDataTypeValue, sValue, lValueLength)        If (lResult = 0) And (Err.Number = 0) Then               If lDataTypeValue = REG_DWORD Then                        td = Asc(Mid$(sValue, 1, 1)) + &H100& * _                Asc(Mid$(sValue, 2, 1)) + &H10000 * _                Asc(Mid$(sValue, 3, 1)) + &H1000000 * _                CDbl(Asc(Mid$(sValue, 4, 1)))                      sValue = Format$(td, "000")              End If              sValue = Left$(sValue, lValueLength - 1)        Else              sValue = "Not Found"        End If        lResult = RegCloseKey(lKeyValue)    ReadRegistry = sValueEnd Function

Top Tip: If when in preview mode, your application is prompting you for a password, try adding an 'IsRunning' global boolean to your screensaver. Then, when your application runs the full screensaver (see Determining the Mode), set this variable to True. In the Unload event of your form, check for this if it is True, prompt for a password. Otherwise, you'll be in preview mode and can simply ignore it. You can also detect whether the screensaver is running is by using a SystemParametersInfo API call.





Page 7 of 8



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel