VB Systeminformation object or similar API from VBA?

I am looking for a way to determine "SmallIconSize", which is described here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation.smalliconsize.aspx
but in VBA in stead of VB.  Is there some API that can be called to get this information?  Trying to figure out what size my system tray icons / NotifyIcons are (I have increased Windows DPI).  I understand I am to determine that from SmallIconSize, but the problem is I've got no idea how to get to it.
(No idea how hard this is, will increase points if needed.)
(I could of course just count pixels on my screen but I want to know how to do this in general.....)
Joe5Asked:
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.

nffvrxqgrcfqvvcCommented:
You can use either of the following:
GetSystemMetrics
http://msdn.microsoft.com/en-us/library/ms724385(VS.85).aspx
TB_GETBUTTONSIZE
http://msdn.microsoft.com/en-us/library/ms940431.aspx

Private Const SM_CXSMICON = 49
Private Const SM_CYSMICON = 50

Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

'Debug.Print GetSystemMetrics(SM_CXSMICON)
'Debug.Print GetSystemMetrics(SM_CYSMICON)

Open in new window

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
Joe5Author Commented:
Awesome!  Thank you!

I accepted the solution already.  If you could also shed some more light on how to use the TB_GETBUTTONSIZE, that would be neat... I read it is a "message"?  How does one use that?
0
nffvrxqgrcfqvvcCommented:
Sure... The message actually need to know the window handle of the system tray area (ToolbarWindow). It returns DWORD of the size of the buttons in the system tray area which you need to convert to two integer values for the width and heights. This might return 18x18 for example it's because there is 2pixel of seperation. Which means the actual icon is about 16x16.
 
Use like :  Call GetTrayButtonSize

Option Explicit

Private Type TRAYBUTTONSIZE
  LoWord      As Integer
  HiWord      As Integer
End Type

Private Const WM_USER = &H400&
Private Const TB_GETBUTTONSIZE = WM_USER + 58

Private Declare Function SendMessageW Lib "user32" ( _
  ByVal hWnd As Long, _
  ByVal wMsg As Long, _
  ByVal wParam As Long, _
  ByVal lParam As Long) As Long
  
Private Declare Function FindWindowExW Lib "user32" ( _
  ByVal hWnd1 As Long, _
  ByVal hWnd2 As Long, _
  ByVal lpsz1 As Long, _
  ByVal lpsz2 As Long) As Long
  
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
  pDst As Any, _
  pSrc As Any, _
  ByVal ByteLen As Long)
  
Public Function FindWindow(ByVal hWnd As Long, ByVal szClass As String) As Long
  ' Finds a window handle if it exists.
  ' Returns the window handle.
  FindWindow = FindWindowExW(hWnd, 0, StrPtr(szClass), 0)
End Function

Public Sub GetTrayButtonSize()
  
  ' Get the system tray button size.
  Dim hWnd        As Long
  Dim dwResult    As Long
  Dim btnSize     As TRAYBUTTONSIZE
  
  hWnd = FindWindow(0, "Shell_TrayWnd")
  hWnd = FindWindow(hWnd, "TrayNotifyWnd")
  hWnd = FindWindow(hWnd, "SysPager")
  hWnd = FindWindow(hWnd, "ToolbarWindow32")

  dwResult = SendMessageW(hWnd, TB_GETBUTTONSIZE, 0, 0)
  
  If dwResult <> 0 Then
    CopyMemory btnSize, dwResult, LenB(btnSize)
    Debug.Print btnSize.LoWord
    Debug.Print btnSize.HiWord
  End If
  
End Sub

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Joe5Author Commented:
I am amazed to get this level of help.  Thank you!
Strangely, the TB_GETBUTTONSIZE code returns 30, 26 as the dimensions, while GetSystemMetrics says they are 20, 20.  The latter is more in line with what I had expected, so I will use that method.  (I am using Windows 7, by the way, don't know if that might have anything to do with the 30,26 result at all.)
0
nffvrxqgrcfqvvcCommented:
Yup it works but the thing to remember is that it's not the actual size of the icon in the system tray but the size of the buttons in the system tray.. In Windows7 if you look close enough while hover your mouse over an icon you can see that the buttons height seems a bit larger then its width so this might indicate that the width is 26pixels and there is 3pixels of seperation from left to right and for the height there is 5 pixels of seperation from, top to bottom if the small icon size is 20x20.
0
Joe5Author Commented:
OK thanks :)  great help.
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
Microsoft Office

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.