Find all our projects in development below.
All source code is GNU General Public License (GPL)
Browsing clsSysToolbar.cls (2.81 KB)
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsSysToolbar"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
' clsSysToolbar: exposes a system tray enumeration interface
'
' Copyright (c) 2008 JaviteSoft ( http://www.javitesoft.com )
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function IsWindowApi Lib "user32" Alias "IsWindow" (ByVal hWnd As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_USER = &H400
Private Const TB_BUTTONCOUNT = (WM_USER + 24)
Private Const TB_COMMANDTOINDEX = (WM_USER + 25)
Private m_hWnd As Long
Public Function Init() As clsSysToolbar
m_hWnd = FindWindow("Shell_TrayWnd", vbNullString)
If IsWindowApi(m_hWnd) Then
m_hWnd = FindWindowEx(m_hWnd, 0, "TrayNotifyWnd", vbNullString)
If IsWindowApi(m_hWnd) Then
m_hWnd = FindWindowEx(m_hWnd, 0, "SysPager", vbNullString)
If IsWindowApi(m_hWnd) Then
m_hWnd = FindWindowEx(m_hWnd, 0, "ToolbarWindow32", vbNullString)
If IsWindowApi(m_hWnd) Then
Set Init = Me
Exit Function
End If
End If
End If
End If
Set Init = Nothing
End Function
Public Property Get Count() As Long
Count = SendMessage(m_hWnd, TB_BUTTONCOUNT, 0, ByVal 0)
End Property
Public Function GetButtonByIndex(ByVal intIndex As Long) As clsToolbarButton
Dim objBtn As New clsToolbarButton
objBtn.Init m_hWnd, intIndex
Set GetButtonByIndex = objBtn
End Function
Public Function GetButtonByCommand(ByVal intCmd As Long) As clsToolbarButton
Dim intIndex As Long
intIndex = SendMessage(m_hWnd, TB_COMMANDTOINDEX, intCmd, ByVal 0)
Dim objBtn As New clsToolbarButton
objBtn.Init m_hWnd, intIndex
Set GetButtonByCommand = objBtn
End Function
Public Property Get hWnd() As Long
hWnd = m_hWnd
End Property
Public Property Get IsWindow() As Boolean
IsWindow = CBool(IsWindowApi(m_hWnd))
End Property