Page 2 of 2

Re: Taskbar?

Posted: Fri Jan 21, 2011 4:17 pm
by dj1437
it would be very hard, there is like 10 errors with like 100 lines in each error, all saying not declared and stuff :P

Re: Taskbar?

Posted: Fri Jan 21, 2011 4:21 pm
by mandai
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.

Re: Taskbar?

Posted: Sat Jan 22, 2011 12:54 am
by dj1437
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;

Re: Taskbar?

Posted: Sun Jan 23, 2011 1:09 pm
by mandai
What are you trying to click on/what are you trying to do?

Re: Taskbar?

Posted: Sun Jan 23, 2011 1:57 pm
by dj1437
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

Re: Taskbar?

Posted: Sun Jan 23, 2011 2:40 pm
by mandai
Try:
Code: Select all
    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