Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleShow the current screen saver
DescriptionThis example shows how to show the current screen saver in Visual Basic 6. It reads System.ini and look for the "boot" section's "SCRNSAVE.EXE" value.
Keywordsscreen saver, INI, INI file, get INI value, Windows directory, get Windows directory
CategoriesWindows, Files and Directories
 
When the program starts, it uses the GetIniString function to read the value of the "boot" section's "SCRNSAVE.EXE" value in System.ini. It uses the GetWindowsDir function to get the Windows directory, where System.ini is located.
 
' Display the current screen saver.
Private Sub Form_Load()
    Dim screen_saver As String
    screen_saver = GetIniString( _
        GetWindowsDir() & "\System.ini", _
        "boot", "SCRNSAVE.EXE", "<none>")
    lblScreenSaver.Caption = screen_saver
End Sub
 
The GetWindowsDir function uses the GetWindowsDirectory API function to see where the Windows directory is on this computer.
 
' Return the Windows directory path.
Private Function GetWindowsDir() As String
Const MAX_PATH_LEN As Integer = 260
Dim win_dir As String
Dim ret_len As Long

    ' Get the windows directory.
    win_dir = Space$(MAX_PATH_LEN)
    ret_len = GetWindowsDirectory( _
        win_dir, Len(win_dir))
    GetWindowsDir = Left$(win_dir, ret_len)
End Function
 
The GetIniString function uses the GetPrivateProfileString API function to read a value from an INI file.
 
' Return the indicated value from an INI file.
Private Function GetIniString(ByVal file_name As String, _
    ByVal section As String, ByVal key_name As String, _
    ByVal default As String) As String
Const MAX_LEN As Integer = 2408
Dim ret_buffer As String
Dim ret_len As Long

    ret_buffer = Space$(MAX_LEN)
    ret_len = GetPrivateProfileString( _
        section, key_name, default, _
        ret_buffer, Len(ret_buffer), file_name)
    GetIniString = Left$(ret_buffer, ret_len)
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated