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
 
 
 
 
 
 
TitleRefresh the desktop's icons
Keywordsdesktop icon size, Registry, regedit
CategoriesTips and Tricks, Windows
 
!!! WARNING !!!
Modifying the Registry can seriously damage your system. If you change the wrong values, you can make your system unbootable. Don't mess with the registry unless you know what you are doing and make a backup first in any case.

Use the GetRegKeyValue function to get the current desktop icon size. Add one and use SetRegKeyValue to save the new value. Then use SendMessageTimeout to broadcast a message telling all toplevel windows that a system setting has changed.

Now change the icon size back. This process makes the toplevel windows refresh their icons.

See the code for details of how GetRegKeyValue and SetRegKeyValue work.

 
Private Sub cmdRefreshIcons_Click()
Dim icon_size_string As String
Dim new_icon_size_string As String
Dim result As Long

    ' Get the current icon size.
    icon_size_string = GetRegKeyValue( _
        HKEY_CURRENT_USER, _
        "Control Panel\Desktop\WindowMetrics", _
        "Shell Icon Size")

    ' Increase the value by 1.
    new_icon_size_string = Format$(CInt(icon_size_string) + _
        1)
    SetRegKeyValue HKEY_CURRENT_USER, _
        "Control Panel\Desktop\WindowMetrics", _
        "Shell Icon Size", new_icon_size_string

    ' Send HWND_BROADCAST to refresh the icons.
    SendMessageTimeout HWND_BROADCAST, WM_SETTINGCHANGE, _
        SPI_SETNONCLIENTMETRICS, 0&, SMTO_ABORTIFHUNG, _
        10000&, result

    ' Restore the original value.
    SetRegKeyValue HKEY_CURRENT_USER, _
        "Control Panel\Desktop\WindowMetrics", _
        "Shell Icon Size", icon_size_string

    ' Send HWND_BROADCAST to refresh the icons again.
    SendMessageTimeout HWND_BROADCAST, WM_SETTINGCHANGE, _
        SPI_SETNONCLIENTMETRICS, 0&, SMTO_ABORTIFHUNG, _
        10000&, result
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated