Get / Set the Icon Size programmatically

The SystemParametersInfo API with
SPI_SETICONMETRICS or SPI_SETICONMETRICS
as the first argument can be used to
get and set the icon details. I have used
a variable of type IconMetrics structure
to retrieve this value. But this structure
does not have a IconSize member at all.
How do I find the iconSize? Is there any
API call to get and set the IconSize?

The code that I used to retrieve the other
details about the icon is enclosed.

Option Explicit
'Gets the system IconMetrics
'The input parameter is a filename in which the icon details are stored
Public Function GetIconMetrics(Value As Variant) As Long
On Error GoTo Err_GetIconMetrics

Dim tIconMetrics As ICONMETRICS
Dim FileNum As Integer
Dim iRet As Integer
Dim i As Long
Dim bEnd As Boolean

tIconMetrics.cbSize = Len(tIconMetrics)
iRet = SystemParametersInfo(SPI_GETICONMETRICS, vbNull, tIconMetrics, 0)
If iRet = 0 Then
    GoTo Err_GetIconMetrics
End If

bEnd = False
For i = 1 To LF_FACESIZE
    If tIconMetrics.lfFont.lfFaceName(i) = 0 Then bEnd = True
    If bEnd = True Then tIconMetrics.lfFont.lfFaceName(i) = 0
Next i

FileNum = FreeFile
Open Value For Binary As #FileNum

Put #1, , tIconMetrics

Close #1
GetIconMetrics = SUCCESS
Exit Function

Err_GetIconMetrics:
    Select Case Err.Number
        Case Else
            MsgBox "Error during Get"
    End Select

End Function

'sets the system IconMetrics
'The input parameter is a filename which has the icon details
Public Function SetIconMetrics(Value As Variant) As Long
On Error GoTo Err_SetIconMetrics

Dim tIconMetrics As ICONMETRICS
Dim FileNum As Integer
Dim iRet As Integer

FileNum = FreeFile
Open Value For Binary As #FileNum

Get #1, , tIconMetrics

Close #1

tIconMetrics.cbSize = Len(tIconMetrics)
iRet = SystemParametersInfo(SPI_SETICONMETRICS, vbNull, tIconMetrics, SPIF_SENDCHANGE)
If iRet = 0 Then
    GoTo Err_SetIconMetrics
End If
Sleep (1500)
DoEvents
iRet = SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0)
DoEvents

SetIconMetrics = SUCCESS
Exit Function

Err_SetIconMetrics:
    Select Case Err.Number
        Case Else
            MsgBox "Error during Set"
    End Select
End Function

Private Sub Form_Load()
    GetIconMetrics ("c:\Icon.txt")
    MsgBox "Get over"
     
    SetIconMetrics ("c:\Icon.txt")
End Sub


This code gives me icon details like
IconSpacing (Horizontal and Vertical) ,
TitleWrapping. But it does not give the
icon size. Any idea how to find it?
qaqaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

qaqaAuthor Commented:
While running the above code in debug mode, I found that tIconMetrics.iHorzSpacing gives me a value that is equal to the IconSize + Horizontal Spacing. Similarly tIconMetrics.iVertSpacing gives a value that is equal to the IconSize + Vertical Spacing. But, how do I find the current IconSize programmatically?
0
Erick37Commented:
Use the GetSystemMetrics API to retrieve the default height and width of an icon.

Dim lRet As Long
lRet = GetSystemMetrics(SM_CXICON)
Debug.Print "Icon width = "; lRet
lRet = GetSystemMetrics(SM_CYICON)
Debug.Print "Icon height = "; lRet
0
qaqaAuthor Commented:
The GetSystemMetrics API gives the default values only. Even if the icon size is different, it gives the default value only. Any other way to find out the current icon size?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Erick37Commented:
P.S.
These values are also available from the registry.

HKEY_CURRENT_USER\Control panel\desktop\WindowMetrics

The Key "Shell Icon Size" contains the current size in pixels of the icon.

If you change this setting in code, you will probably have to send a "refresh" message in order for the changes to show:

PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
0
Erick37Commented:
Here is some info from Microsoft:

http://msdn.microsoft.com/library/techart/msdn_icons.htm

Read the section "When in Windows."
This section gives C code for changing the icon size by modifying the registry value.  Apparantly this is the only way to do it.

Here is a Bas module with registry functions for VB:

http://www.thescarms.com/vbasic/Registry.htm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
qaqaAuthor Commented:
Thanks for the info.My problem is solved. Also, Please do let me know if you come across any API call like 'SystemParametersInfo' to accomplish the above. Thanks once again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.