Re: Taskbar?
Posted: Fri Jan 21, 2011 4:17 pm
it would be very hard, there is like 10 errors with like 100 lines in each error, all saying not declared and stuff :P
Sharing, Teaching and Supporting coders of all ages and levels since 2009
https://www.codenstuff.com/forum/
mandai wrote:If you get a warning about System.Windows.Automation not being available then you might need to install the UI Automation package from Microsoft. You will also have to add references to UIAutomationClient and UIAutomationTypes in your project.thanks, it works now, but when i click something nothing happens :( dunnno; dunnno;
mandai wrote:What are you trying to click on/what are you trying to do?i am trying to click the tasks and nothing happens, and i put a timer so it refreshes every five seconds
Delegate Sub clearItems()
Sub del_clearItems()
ListBox1.Items.Clear()
End Sub
Delegate Sub addItem(ByVal item As String)
Sub del_addItem(ByVal item As String)
ListBox1.Items.Add(item)
End Sub
Dim aec As AutomationElementCollection
Dim collectionIndex As List(Of Integer) = New List(Of Integer)
Dim taskbar As AutomationElement
Sub t_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
ListBox1.Invoke(New clearItems(AddressOf del_clearItems))
collectionIndex.Clear()
aec = taskbar.FindAll(TreeScope.Descendants, Condition.TrueCondition)
Dim adding As Boolean = False
For i As Integer = 0 To aec.Count - 1
If aec(i).Current.Name.ToLower() = "running applications" Then 'applications is lower case in win7
adding = True
Continue For
End If
If adding Then
collectionIndex.Add(i)
ListBox1.Invoke(New addItem(AddressOf del_addItem), aec(i).Current.Name)
End If
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim taskbarHandle As IntPtr = FindWindow("Shell_TrayWnd", Nothing)
taskbar = AutomationElement.FromHandle(taskbarHandle)
Dim t As System.Timers.Timer = New System.Timers.Timer()
t.Interval = 5000
AddHandler t.Elapsed, AddressOf t_Elapsed
t_Elapsed(Nothing, Nothing)
t.Start()
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
If ListBox1.SelectedIndex > -1 Then
Try
Dim ip As InvokePattern = aec(collectionIndex(ListBox1.SelectedIndex)).GetCurrentPattern(InvokePattern.Pattern)
ip.Invoke()
Catch ex As Exception
t_Elapsed(Nothing, Nothing)
End Try
End If
End Sub